手机ssh连接linux_ssh建立连接速度缓慢怎么解决

更新时间:2020-03-26    来源:linux    手机版     字体:

【www.bbyears.com--linux】

ssh/scp是很常用的命令,发现对有些主机, ssh建立连接速度特别慢,连接建立之后执行操作速度却很正常。

用 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 关掉它问题即解决。

如果上面办法解决不了,我们可以接着来排查

下面说下如何解决这样的问题,最为常见的原因是因为server的sshd会去DNS查找访问
client IP的hostname,如果DNS不可用或者没有相关记录,就会耗费大量时间。
 
  1、在server上/etc/hosts文件中把你本机的ip和hostname加入
 
  2、在server上/etc/ssh/sshd_config文件中修改或加入UseDNS=no,另外在authentication gssapi-with-mic也有可能出现问题,在server上/etc/ssh/sshd_config文件中修改GSSAPIAuthentication no.


3、修改server上/etc/nsswitch.conf中hosts为hosts: files
 
  4、reboot server使配置生效
 
 /etc/init.d/sshd restart重启sshd进程使配置生效。
 
  
项目组的服务器,通过SSH服务远程访问Linux服务器,总是等待很久才能登陆。


试过下面的方法,再通过SSH服务远程访问Linux服务器,瞬间登陆。。。甚是开心。。。


vi /etc/ssh/sshd_config


关闭 SSH 的 DNS 反解析,添加下面一行:


UseDNS no


※虽然配置文件中[UseDNS yes]被注释点,


但默认开关就是yes...(SSH服务默认启用了DNS反向解析的功能)

本文来源:http://www.bbyears.com/caozuoxitong/89701.html