SecureCRT链接时很快,链接成功后进去要等十几秒才显示内容,才能操做,操做时也很快php
解决方法html
vi /etc/ssh/sshd_configlinux
查找 UseDNS编程
确保是ubuntu
UseDNS nowindows
service sshd restartapi
下面是其实的状况,从网上搞来的安全
解决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 或者 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致使,可分别使用如下几种分析处理方式
一、在server上/etc/hosts文件中把你本机的ip和hostname加入
二、在server上/etc/ssh/sshd_config文件中修改或加入UseDNS=no
三、注释掉server上/etc/resolv.conf中不使用的IP全部行
四、修改server上/etc/nsswitch.conf中hosts为hosts:files
五、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