ssh连接超慢解决
2015-09-10 10:40
183 查看
手头有台Linux服务器ssh登录时超级慢,需要几十秒。其它服务器均没有这个问题。平时登录操作都默默忍了。今天终于忍不住想搞清楚到底什么原因。搜索了一下发现了很多关于ssh登录慢的资料,于是自己也学着来分析、印证一下ssh登录慢的原因。
出现ssh登录慢一般有两个原因:DNS反向解析的问题和ssh的gssapi认证
1:ssh的gssapi认证问题
GSSAPI(GenericSecurityServicesApplicationProgrammingInterface)是一套类似Kerberos5的通用网络安全系统接口。该接口是对各种不同的客户端服务器安全机制的封装,以消除安全接口的不同,降低编程难度。但该接口在目标机器无域名解析时会有问题
默认情况下,GSSAPIAuthentication在服务器端和客户端都激活的。如果DNS服务出现问题,那么登录过程要等到DNS查询超时后才能继续,这就是为什么SSH登录提示符要等很久才出现的原因。为什么ssh登录过程中要用到DNS解析服务呢?这个是GSSAPI认证方式需要的缘故。
所以在配置文件/etc/ssh/sshd_config(服务器)或/etc/ssh/ssh_config(客户端)将参数GSSAPIAuthentication设置为no可以解决ssh登录慢的问题。
2:DNS反向解析的问题
OpenSSH在用户登录的时候会验证IP,它根据用户的IP使用反向DNS找到主机名,再使用DNS找到IP地址,最后匹配一下登录的IP是否合法。如果客户机的IP没有域名,或者DNS服务器很慢或不通,那么登录就会很花时间。
问题分析:
首先可以在ssh命令后面加上“-v“参数,输出debug信息定位问题。具体操作为ssh-vroot@serverip
[/code]
[/code]
从上面输出信息看到有关于UnspecifiedGSSfailure,于是我将/etc/ssh/sshd_config(服务器)或/etc/ssh/ssh_config(客户端)将参数GSSAPIAuthentication设置为no,重启了sshd服务,测试发现ssh登录还是很慢。
[/code]
[/code]
那么原因应该是DNS反向解析的问题,关于DNS反向解析的问题有几个解决方法:
1:在server上/etc/hosts文件中把常用的ip和hostname加入,然后在/etc/nsswitch.conf看看程序是否先查询hosts文件
2:在server上/etc/ssh/sshd_config文件中修改或加入UseDNS=no。然后重启sshd服务
我在/etc/ssh/sshd_config上将UseDNS设置为no,重启sshd服务后,然后测试ssh连接速度。果然飞快连接上。看来主要还是DNS反向解析的问题。
出现ssh登录慢一般有两个原因:DNS反向解析的问题和ssh的gssapi认证
1:ssh的gssapi认证问题
GSSAPI(GenericSecurityServicesApplicationProgrammingInterface)是一套类似Kerberos5的通用网络安全系统接口。该接口是对各种不同的客户端服务器安全机制的封装,以消除安全接口的不同,降低编程难度。但该接口在目标机器无域名解析时会有问题
默认情况下,GSSAPIAuthentication在服务器端和客户端都激活的。如果DNS服务出现问题,那么登录过程要等到DNS查询超时后才能继续,这就是为什么SSH登录提示符要等很久才出现的原因。为什么ssh登录过程中要用到DNS解析服务呢?这个是GSSAPI认证方式需要的缘故。
所以在配置文件/etc/ssh/sshd_config(服务器)或/etc/ssh/ssh_config(客户端)将参数GSSAPIAuthentication设置为no可以解决ssh登录慢的问题。
2:DNS反向解析的问题
OpenSSH在用户登录的时候会验证IP,它根据用户的IP使用反向DNS找到主机名,再使用DNS找到IP地址,最后匹配一下登录的IP是否合法。如果客户机的IP没有域名,或者DNS服务器很慢或不通,那么登录就会很花时间。
问题分析:
首先可以在ssh命令后面加上“-v“参数,输出debug信息定位问题。具体操作为ssh-v
[code] [code][root@localhost~]#ssh-vroot@192.168.xxx.xxx
OpenSSH_4.3p2,OpenSSL0.9.8e-fips-rhel501Jul2008
debug1:Readingconfigurationdata/etc/ssh/ssh_config
debug1:Applyingoptionsfor*
debug1:Connectingto192.168.xxx.xxx[192.168.xxx.xxx]port22.
debug1:Connectionestablished.
debug1:permanently_set_uid:0/0
debug1:identityfile/root/.ssh/identitytype-1
debug1:identityfile/root/.ssh/id_rsatype-1
debug1:identityfile/root/.ssh/id_dsatype-1
debug1:loaded3keys
debug1:Remoteprotocolversion2.0,remotesoftwareversionOpenSSH_4.3
debug1:match:OpenSSH_4.3patOpenSSH*
debug1:Enablingcompatibilitymodeforprotocol2.0
debug1:LocalversionstringSSH-2.0-OpenSSH_4.3
debug1:SSH2_MSG_KEXINITsent
debug1:SSH2_MSG_KEXINITreceived
debug1:kex:server->clientaes128-ctrhmac-md5none
debug1:kex:client->serveraes128-ctrhmac-md5none
debug1:SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192)sent
debug1:expectingSSH2_MSG_KEX_DH_GEX_GROUP
debug1:SSH2_MSG_KEX_DH_GEX_INITsent
debug1:expectingSSH2_MSG_KEX_DH_GEX_REPLY
Theauthenticityofhost'192.168.xxx.xxx(192.168.xxx.xxx)'can'tbeestablished.
RSAkeyfingerprintis04:08:57:22:7e:8d:dc:d3:8e:91:20:d0:ba:d9:ed:78.
Areyousureyouwanttocontinueconnecting(yes/no)?yes
Warning:Permanentlyadded'192.168.xxx.xxx'(RSA)tothelistofknownhosts.
debug1:ssh_rsa_verify:signaturecorrect
debug1:SSH2_MSG_NEWKEYSsent
debug1:expectingSSH2_MSG_NEWKEYS
debug1:SSH2_MSG_NEWKEYSreceived
debug1:SSH2_MSG_SERVICE_REQUESTsent
debug1:SSH2_MSG_SERVICE_ACCEPTreceived
debug1:Authenticationsthatcancontinue:publickey,gssapi-with-mic,password
debug1:Nextauthenticationmethod:gssapi-with-mic
debug1:UnspecifiedGSSfailure.Minorcodemayprovidemoreinformation
Nocredentialscachefound
debug1:UnspecifiedGSSfailure.Minorcodemayprovidemoreinformation
Nocredentialscachefound
debug1:UnspecifiedGSSfailure.Minorcodemayprovidemoreinformation
Nocredentialscachefound
debug1:Nextauthenticationmethod:publickey
debug1:Tryingprivatekey:/root/.ssh/identity
debug1:Tryingprivatekey:/root/.ssh/id_rsa
debug1:Tryingprivatekey:/root/.ssh/id_dsa
debug1:Nextauthenticationmethod:password
root@192.168.xxx.xxx'spassword:
debug1:Authenticationsucceeded(password).
debug1:channel0:new[client-session]
debug1:Enteringinteractivesession.
debug1:Sendingenvironment.
debug1:SendingenvLANG=en_US.UTF-8
Lastlogin:SunSep608:30:472015from192.168.7.222
[root@ceglnx01~]#
[/code]
[/code]
从上面输出信息看到有关于UnspecifiedGSSfailure,于是我将/etc/ssh/sshd_config(服务器)或/etc/ssh/ssh_config(客户端)将参数GSSAPIAuthentication设置为no,重启了sshd服务,测试发现ssh登录还是很慢。
[code]
[code][root@localhost~]#servicesshdstatus
openssh-daemon(pid3594)isrunning...
[root@localhost~]#servicesshdrestart
Stoppingsshd:[OK]
Startingsshd:[OK]
[/code]
[/code]
那么原因应该是DNS反向解析的问题,关于DNS反向解析的问题有几个解决方法:
1:在server上/etc/hosts文件中把常用的ip和hostname加入,然后在/etc/nsswitch.conf看看程序是否先查询hosts文件
2:在server上/etc/ssh/sshd_config文件中修改或加入UseDNS=no。然后重启sshd服务
我在/etc/ssh/sshd_config上将UseDNS设置为no,重启sshd服务后,然后测试ssh连接速度。果然飞快连接上。看来主要还是DNS反向解析的问题。
相关文章推荐
- 【Unity3D】3D角色换装++ Advance
- eclipse设置maven加载国内镜像
- 求一个数阶乘的位数
- mysql数据库MyISAM与InnoDB比较与选择
- 专访Tiny框架创始人悠然:好的软件设计是“品”出来的
- 大小端字节序
- 后缀表达式 转 表达式树
- 2.Ionic 环境搭建(ios创建环境运行)
- 通用List查询
- 【Unity3d】3d角色换装实现原理及步骤
- iPhone开发之导航控制器的预习——UINavigationController导航控制器的学习
- Android HttpURLConnection.getContentLength() 等于 -1
- 学习STL,实现一个单链表的迭代器
- UIViewController生命周期
- Hibernate annotations
- jquery validate验证插件
- HTML5的崛起之路
- HDU 5430 Reflect
- 【1】基于TQ2440的MP3设计——【4、U-Boot 移植与改写】
- Sql server management studio: cannot find one or more components