SSH远程登陆服务器要很久才出现输入密码界面怎么办

经常通过ssh远程主机,同样是 Linux 主机,其中一些创建 ssh 连接速度特别慢,连接建立之后执行操作速度却很正常,看来应该不是网络原因。解决的方法是通过ssh-vv参数来查看调试信息的:

经常遇到情况有两种:

一、GSSAPIAuthentication认证失败问题。

ssh -vv 来查看并分析连接过程中的问题,发现连接过程中会停留在这里好久:

debug1:Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method:
gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found

debug1:Unspecified GSS failure. Minor code may provide more information
No credentials cache found

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

debug1:Next authentication method: publickey


原来是因为尝试了个gssapi-with-mic认证方式失败浪费了时间,打开(本机的或者说是客户端的)/etc/ssh/ssh_config把里面的GSSAPIAuthentication yes改成no 关掉它并重启sshd服务,即可让 ssh直接尝试password认证方式。

禁用 GSSAPIAuthentication前后建立 ssh连接时间的对比:

view plaincopy to clipboardprint?
[root@knight95 ~]# time ssh root@192.168.1.96

root@192.168.1.96's password:

Last login: Thu Jan  5 05:44:30 2017 from 192.168.1.95

[root@knight96 ~]# exit

logout

Connection to 192.168.1.96 closed.

 

real  0m3.303s

user 0m0.015s

sys   0m0.016s

[root@knight95 ~]#


二、DNS问题

SSH 登录太慢可能是 DNS 解析的问题,默认配置下 sshd 初次接受 ssh 客户端连接的时候会自动反向解析客户端 IP 以得到 ssh 客户端的域名或主机名。

如果这个时候 DNS 的反向解析不正确,sshd 就会等到 DNS 解析超时后才提供 ssh 连接,这样就造成连接时间过长、ssh 客户端等待的情况,一般为10-30秒左右。有个简单的解决办法就是在 sshd 的配置文件(sshd_config)里取消 sshd 的反向 DNS 解析。

#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes

默认情况下是以上格式,没有显式的设置GSSAPITrustDNS为 no ,需要把这一行取消注释,然后重启sshd服务再进行连接。

综上:在连接过程中可以用ssh -vv root@DestIP 来Debug连接过程,最终找到问题。








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值