尝试通过 SSH 连接到系统时出现延迟
Posted
技术标签:
【中文标题】尝试通过 SSH 连接到系统时出现延迟【英文标题】:Delay when attempting to SSH to a system 【发布时间】:2013-11-21 11:49:59 【问题描述】:当我尝试从我的系统 ssh 到朋友的系统时,我面临大约 5-6 秒的延迟。这是命令的详细输出:
zeus@athena:~$ ssh -v ashwin@192.168.40.211
OpenSSH_5.3p1 Debian-3ubuntu7, OpenSSL 0.9.8k 25 Mar 2009
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.40.211 [192.168.40.211] port 22.
debug1: Connection established.
debug1: identity file /home/zeus/.ssh/identity type -1
debug1: identity file /home/zeus/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/zeus/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0p1 Debian-3ubuntu1
debug1: match: OpenSSH_6.0p1 Debian-3ubuntu1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3p1 Debian-3ubuntu7
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr 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.40.211' is known and matches the RSA host key.
debug1: Found key in /home/zeus/.ssh/known_hosts:71
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
<---- delay 4-5 seconds------>
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/zeus/.ssh/identity
debug1: Offering public key: /home/zeus/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/zeus/.ssh/id_dsa
debug1: Next authentication method: password
有人可以帮我弄清楚如何摆脱这种延迟吗?
【问题讨论】:
一个常见的 DNS 问题。见superuser.com/questions/372238 和sysadvent.blogspot.nl/2010/12/… 这很有帮助。谢谢。 【参考方案1】:正如 cmets 中所建议的,这可能是 DNS 问题。有一篇文章介绍了尝试解决此问题的一些步骤: http://www.thegeekstuff.com/2010/07/openssh-slow-at-ssh2_msg_service_accept-received/
给出的建议归结为编辑/etc/sshd_config
添加/更改UseDNS no
,然后重新启动sshd。显然,如果不访问服务器,这可能会很棘手!
还应该指出,从长远来看,将UseDNS
设置为no
可能不是最佳解决方案。如果有问题的话,最好解决机器上的 DNS 问题。
【讨论】:
【参考方案2】:我的问题似乎在这里有了答案:
https://superuser.com/a/654153/152271
似乎远程主机试图对我的主机名(连接的主机名)进行 nslookup。在远程主机中编辑 /etc/hosts 添加我的 IP/主机名后,它修复了延迟。
【讨论】:
以上是关于尝试通过 SSH 连接到系统时出现延迟的主要内容,如果未能解决你的问题,请参考以下文章
在 Mac OSx 上通过 SSH 连接到 EC2 时出现权限错误
尝试连接到 dask 仪表板时出现“404 Not found”
使用 VS Code Remote 连接到 Windows OpenSSH 时出现问题