内网用SSH连接Linux很慢

网上关于该问题的常用解决方法是(主要就是修改配置文件/etc/ssh/sshd_config):

(1)修改"UseDNS"的值为“no”(没有的添加该配置选项,注释掉的放开即可);这种修改在我的系统里面好像没起作用!

(2)修改“GSSAPIAuthentication”的值为“no”(没有的添加该配置选项,注释掉的放开即可);

其实用户可以自己运行“ssh -v host”进行debug的,通过debug信息就可以看到连接到什么地方被耽搁了;我的测试就是在"debug1: Unspecified GSS failure. Minor code may provide more information" 这里停顿了一会儿,所以感觉修改“GSSAPIAuthentication”的值应该会有效果,但实践证明,如果不改上面几项,该处更改在我的系统依然不起作用!

解决ssh连接慢(有时候等半分钟才出现密码输入提示)的方法

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

用 ssh -v 来查看详细的连接建立过程,马上用一台建立连接很慢的主机试了一下,在一大堆输出信息中发现在这里停留最久:

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 关掉它,即可让 ssh 直接尝试美妙的 publickey 认证方式。

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

view plaincopy to clipboardprint?
root@server:~$ time ssh root@192.168.10.1 exit

real 0m18.488s
user 0m0.004s
sys 0m0.008s
root@server:~$ time ssh root@192.168.10.1 exit

real 0m3.531s
user 0m0.016s
sys 0m0.000s

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/22800.html