Fixing ssh login long delay

原文:http://injustfiveminutes.com/2013/03/13/fixing-ssh-login-long-delay/

For a long time I had a problem with ssh login on a Redhat 6 server – it was taking too long to connect to it, around 30 seconds. Normally it hasn’t been a big issue – after all, you connect once and work for all day as long as you enable server keepalive packetsto avoid session timeout.

However when it comes to work with SFTP o GIT it might become annoying. Everytime you sFTP upload or  git push you have to wait 30 seconds again.

This kind of problems are often related to DNS issues but this is not always the case. Following are the most common solutions:

1. Disable reverse IP resolution on SSH server

It turns out there is a setting in OpenSSH that controls whether SSHd should not only resolve remote host names but also check whether the resolved host names map back to remote IPs. Apparently, that setting is enabled by default in OpenSSH. The directiveUseDNS controls this particular behaviour of OpenSSH, and while it is commented in sshd_config (which is the default configuration file for the OpenSSH daemon in most enviornments), as per the man page for sshd_config, the default for UseDNS is set to enabled. Add the following line:

UseDNS no

2. DNS resolver fix for IPv4/IPv6 enabled stacks

It’s a known issue on the Red Hat knowledgebase article DOC-58626, but since it’s closed without login, I’ll share the solution below:

The resolver uses the same socket for the A and AAAA requests. Some hardware mistakenly only sends back one reply. When that happens the client sytem will sit and wait for the second reply. Turning this option on changes this behavior so that if two requests from the same port are not handled correctly it will close the socket and open a new one before sending the second request.

The solution is to add the following line to your /etc/resolv.conf. Just add it all the way at the bottom, as the last line.

options single-request-reopen

3. Disable GSSAPI authentication method

OpenSSH server enables by default theGSSAPI key exchange which allows you to leverage an existing key management infrastructure such as Kerberos or GSI, instead of having to distribute ssh host keys throughout your organisation. With GSSAPI key exchange servers do not need ssh host keys when being accessed by clients with valid credentials.

If you are not using GSSAPI as a authentication mecanism, it might be causing this connection delay.

In my particular case, I ran ssh -v myserver to find out that it was hanging whilst attempting to authenticate with GSSAPI, with the slow section looking like:

....
....
debug2: key: /home/user/.ssh/id_rsa (0xb961d7a8)
debug2: key: /home/user/.ssh/id_dsa ((nil))
debug2: key: /home/user/.ssh/id_ecdsa ((nil))
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup gssapi-keyex
debug3: remaining preferred: gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-keyex
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug2: we did not send a packet, disable method
debug3: authmethod_lookup gssapi-with-mic
debug3: remaining preferred: publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file ‘/tmp/krb5cc_1000‘ not found

debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file ‘/tmp/krb5cc_1000‘ not found

debug1: Unspecified GSS failure.  Minor code may provide more information

Turned out that it was stalling after trying gssapi-with-mic authentication method. Had several “Unspecified GSS failure” messages with several seconds delay between them, therefore it was definitely the root cause of long delays.

The fix is simple – disable attempts to use GSS-API by adding the following to /etc/sshd_config (server side) or yout ~/.ssh/ssh_config (client side).

GSSAPIAuthentication no

There is an easy way to check beforehand whether this solution will work. Try to ssh into your server by disabling GSSAPI authentication:

ssh -o GSSAPIAuthentication=no [email protected]
时间: 2024-08-03 23:07:58

Fixing ssh login long delay的相关文章

ssh login without password

1. ssh-keygen Shufengs-iMac:~ wangbo$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/wangbo/.ssh/id_rsa): [enter-return] Enter passphrase (empty for no passphrase): <span style="font-family: Arial, H

ssh login nova vm

$ sudo cat >> /usr/bin/nova-ssh  << END FIRST=$1 IDX=`expr index $1 "@"`if [[ $IDX  == "0" ]] ; then    echo "please input the user name"    exit 1fiUSER=${FIRST%@*} IP=${FIRST#*@}NINFO=`nova list | grep $IP | awk

【转载】SSH login without password 免密登陆

Your aim You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script. How to

Security configuration of SSH login entry - enterprise security practice

catalog 0. 引言 1. 修改ssh端口 2. 禁用root远程ssh登录 3. 只使用SSH v2 4. 限制用户的SSH访问 5. 禁用.rhosts文件 6. 禁用基于主机的身份验证 7. 基于公私钥的证书登录 8. Linux SSH配置基线检查 0. 引言 关于企业IT系统建设安全性问题在任何时候都不会成为一个过时的话题,企业在构建适合自己业务需求的IT系统之初以及整个IT系统生命周期内,系统的安全运行都是一项非常重要的工作,安全健康体检主要着眼于服务器的入口安全,SSH服务是

java login using ssh framework

layout for ssh login: web.xml: login.jsp: success.jsp: struts.xml: spring-dispatcher.xml: <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http://www

LinuxShell脚本之利用rsync+ssh实现Linux文件系统远程备份

功能介绍: 该脚本用于定期(结合crontab一起使用)将本地目录通过rsync+ssh传输到远程服务器,每次执行都生成一个带有以时间命名的目录,并且当前最新版本的数据链接到一个名字叫current的符号链接上,便于查找和恢复.在数据传输完成前,会传输到临时目录下,这个临时目录被命名为"时间-incomplete".超过10天的备份将被删除,超过10天的日志文件也将被删除. 运行原理: 脚本运行的核心就在于ssh的互信和rsync命令.利用rsync能实现压缩传输,节省传输时间. 感谢

ssh 登陆进去后, .bashrc 也没有被执行

查了一下,ssh login 之后, 会执行 .bash_profile 于是新建一个.bash_profile , 内容如下 if [ -f ~/.bashrc ]; then . ~/.bashrc fi

Myeclipse搭建ssh框架

1.创建项目 打开Myeclipse8.6,新建web工程,命名为ssh,点击完成. 获得目录结构如下: 2为项目添加Struts能力 ????a)右键点击项目,选择MyEclipse->Add Struts Capabilities,或者点击菜单栏中MyEclipse->Project Capabilities->Add Struts Capabilities. b)选择struts2.1版本 c)点击下一步,选择Struts Core(核心库)和Struts 2 Spring(包含集

通过WindowsServer2008R2 NPS完成对Cisco设备的Telnet/SSH 的Radius认证

大家知道对于一个稍具规模的公司来说,网络设备几乎都在几十台到上百台,对于日常的管理来说如果只通过本地账号管理设备登陆是非常繁琐的,尤其是网络工程师流动性比较大的公司.对于入离职流程过程中的账号增删改不是一个小的工作量,所以我们就需要一个统一的登陆方式比如通过Raidus. 下面是拿Cisco和Windows NPS 来举例说明: Cisco  SSH 配置: 第一步开启交换机的SSH: enable secret password ip domain-name contosoc.om usern