SecureCRT连接时很快,连接成功后进去要等十几秒才显示内容,才能操作,操作时也很快

解决方法

vi /etc/ssh/sshd_config

查找 UseDNS

确保是

UseDNS  no

service sshd restart



下面是其实的情况,从网上搞来的

解决Linux系统ssh连接太慢的问题

如果是ssh到远程主机,由于网络快慢等诸多因素,慢一点是很正常的;但如果ssh到本地的某一台主机,也需要等待30s左右,就让人有些无法忍受了!
自从使用debian(版本lenny,以前使用ubuntu6.06时候并没有这个问题)以来,这个问题就存在了,但一直没有时间来解决(或是有尝试过,但失败了),今天终于忍耐不住,到debian mailing-list上问了一下,然后结合自己的实践,基本有些结论了!

根据网上的帖子以及各位网友的提议,感觉这个问题的解决方法好像并不是通用的。不过也没关系,所涉及修改的也就那么几处,如果遇到类似问题,都尝试一下应该就能找到解决的方法了!

我的问题症状: ssh lan_host,需要等待至少30秒才能看到Password的输入提示(网上说这是因为dns反查所造成的);
我的解决方法:需要修改两个配置文件,/etc/resolv.conf 和 /etc/nsswitch.conf

在/etc/resolv.conf里面配置一个正式点dns,原来使用的是192.168.1.1,上网是没有问题的,但这里需要改成一个类似222.xx.xx.xx的域名才行;(我对域名这块没怎么研究,不知道该如何正确表述)
对于/etc/nsswitch.conf,需要将:“hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4” 改成 "hosts: files dns",这种修改,相当于禁止掉了mdns的使用,而只使用dns进行解析;
然后重启sshd服务。
关于mdns:主要是用来解决zeroconf的问题,一般用于局域网内来解析主机名。在linux中的实现是,每个主机运行一个mdns的daemon,让客户地查询的时候,返回自己的主机名。譬如你的主机名叫做abc,那么如果你在nsswitch.conf里面配置了需要支持mdns解析的话,那么你就可以通过ping abc.local, ssh abc.local等来访问这个机器。其实实质上应该是gethostbyname那里读取了nsswitch.conf,然后调用相应的实现来获取地址的。它的好处是,不用配置。(更多详情可参见: http://www.multicastdns.org/

网上关于该问题的常用解决方法是(主要就是修改配置文件/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”的值应该会有效果,但实践证明,如果不改上面几项,该处更改在我的系统依然不起作用!

http://www.linuxdiyf.com/viewarticle.php?id=152141


解决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

http://blog.csdn.net/imfinger/article/details/6403148


linux ssh连接慢

最近发现ssh连接的时候却很慢,ping的速度非常好,让人误以为是ssh连接不上。
分析结果,主要原因为:DNS的解析IP导致,可分别使用以下几种分析处理方式
1、在server上/etc/hosts文件中把你本机的ip和hostname加入 
2、在server上/etc/ssh/sshd_config文件中修改或加入UseDNS=no 
3、注释掉server上/etc/resolv.conf中不使用的IP所有行 
4、修改server上/etc/nsswitch.conf中hosts为hosts:files
5、authentication gssapi-with-mic也有可能出现问题,在server上/etc/ssh/sshd_config文件中修改GSSAPIAuthentication no。/etc/init.d/sshd restart重启sshd进程使配置生效。
如之前为服务器配置了双网卡,使的在/etc/resolv.conf文件中多了一行目前不使用的IP地址。注释或者删除该行即可。

http://blog.chinaunix.net/uid-261392-id-2138927.html

ssh 连接慢解决办法

现象:在局域网内,能ping通目标机器,并且时延是微秒级。
用ssh连局域网内其他linux机器,会等待10-30秒才有提示输入密码。严重影响工作效率。

CentOS修改后效果一样
=================================
客户端操作系统版本:

cat /etc/lsb-release

DISTRIB_ID=Ubuntu

DISTRIB_RELEASE=9.10

DISTRIB_CODENAME=karmic

DISTRIB_DESCRIPTION="Ubuntu 9.10"0

=================================

调试信息:

[root@IBM ~]# ssh -v 10.10.10.100
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 10.10.10.100 [10.10.10.100] port 22.
debug1: connect to address 10.10.10.100 port 22: Connection refused
ssh: connect to host 10.10.10.100 port 22: Connection refused

----------------[网络上的调试信息]----------------------
ssh -v 192.168.12.16  
OpenSSH_5.1p1 Debian-6ubuntu2, OpenSSL 0.9.8g 19 Oct 2007  
debug1: Reading configuration data /etc/ssh/ssh_config  
debug1: Applying options for *  
debug1: Connecting to 192.168.12.16 [192.168.12.16] port 22.  
debug1: Connection established.  
debug1: identity file /home/zhouhh/.ssh/identity type -1  
debug1: identity file /home/zhouhh/.ssh/id_rsa type -1  
debug1: identity file /home/zhouhh/.ssh/id_dsa type -1  
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3  
debug1: match: OpenSSH_4.3 pat OpenSSH_4*  
debug1: Enabling compatibility mode for protocol 2.0  
debug1: Local version string SSH-2.0-OpenSSH_5.1p1 Debian-6ubuntu2  
debug1: SSH2_MSG_KEXINIT sent  
debug1: SSH2_MSG_KEXINIT received  
debug1: kex: server->client aes128-cbc hmac-md5 none  
debug1: kex: client->server aes128-cbc hmac-md5 none  
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent  
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP  
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent  
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY  
debug1: Host '192.168.12.16' is known and matches the RSA host key.  
debug1: Found key in /home/zhouhh/.ssh/known_hosts:1  
debug1: ssh_rsa_verify: signature correct  
debug1: SSH2_MSG_NEWKEYS sent  
debug1: expecting SSH2_MSG_NEWKEYS  
debug1: SSH2_MSG_NEWKEYS received  
debug1: SSH2_MSG_SERVICE_REQUEST sent  
debug1: SSH2_MSG_SERVICE_ACCEPT received  
debug1: Authentications that can continue: publickey,gssapi-with-mic,password  
debug1: Next authentication method: gssapi-with-mic  
debug1: An invalid name was supplied  
Cannot determine realm for numeric host address  
debug1: An invalid name was supplied  
Cannot determine realm for numeric host address  
debug1: An invalid name was supplied  
debug1: Next authentication method: publickey  
debug1: Trying private key: /home/zhouhh/.ssh/identity  
debug1: Trying private key: /home/zhouhh/.ssh/id_rsa  
debug1: Trying private key: /home/zhouhh/.ssh/id_dsa  
debug1: Next authentication method: password  
password:    
debug1: Authentication succeeded (password).  
debug1: channel 0: new [client-session]  
debug1: Entering interactive session.  
debug1: Sending environment.  
debug1: Sending env LANG = zh_CN.UTF-8  
Last login: Fri Dec 25 13:35:04 2009 from 192.168.11.146

可以看到如下的错误信息:

debug1: Next authentication method: gssapi-with-mic
debug1: An invalid name was supplied
Cannot determine realm for numeric host address

事实上,正是从gssapi-with-mic这一行开始,开始耗时间。

失败的尝试:

有人说是在目标机器中修改/etc/ssh/sshd_conf文件

将UseDNS 的缺省值由yes修改为no,并重启sshd。我试了,对这种情况不管用。但不排除对别的延迟情况管用。

====================

有效的解决办法:

修改本地机器的hosts文件,将目标机器的IP和域名加上去。或者让本机的DNS 服务器能解析目标地址。
vi /etc/hosts

192.168.12.16 ourdev

其格式是“目标机器IP 目标机器名称”这种方法促效。没有延迟就连上了。不过如果给每台都加一个域名解析,挺辛苦的。但在windows下用putty或secure-crt时可以采用这种方法。

2.修改本机的客户端配置文件ssh_conf,注意,不是sshd_conf

vi /etc/ssh/ssh_conf

找到

GSSAPIAuthentication yes

改为

GSSAPIAuthentication no

保存。

再连目标机器,速度就飞快了。

GSSAPI ( Generic Security Services Application Programming Interface) 是一套类似Kerberos 5 的通用网络安全系统接口。该接口是对各种不同的客户端服务器安全机制的封装,以消除安全接口的不同,降低编程难度。但该接口在目标机器无域名解析时会有问题。我看到有人给Ubuntu提交了相关bug, 说要将GSSAPIAuthentication的缺省值设为no,不知为何,ubuntu9.10的缺省值还是yes。


修改完毕,此时的连接调试数据变为了:


view plaincopy to clipboardprint?
ssh -v 192.168.12.16
OpenSSH_5.1p1 Debian-6ubuntu2, OpenSSL 0.9.8g 19 Oct 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.12.16 [192.168.12.16] port 22.
debug1: Connection established.
debug1: identity file /home/zhouhh/.ssh/identity type -1
debug1: identity file /home/zhouhh/.ssh/id_rsa type -1
debug1: identity file /home/zhouhh/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.1p1 Debian-6ubuntu2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '192.168.12.16' is known and matches the RSA host key.
debug1: Found key in /home/zhouhh/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/zhouhh/.ssh/identity
debug1: Trying private key: /home/zhouhh/.ssh/id_rsa
debug1: Trying private key: /home/zhouhh/.ssh/id_dsa
debug1: Next authentication method: password
password:

http://www.linuxidc.com/Linux/2013-02/79898.htm

http://www.linuxidc.com/Linux/2013-02/79898p2.htm