ssh 连接速度非常慢

ssh 连接速度非常慢

我有几个远程系统,其中一个是运行 debian 的 linode,通过 ssh 进入的速度非常慢 - 每次大约需要 20-25 秒。这似乎是最近发生的。我已经尝试按照类似问题的几个答案中的建议设置GSSAPIAuthenticationno或 to yes,但没有什么区别。如果我使用 FQDN 或 IP 地址登录也没有任何区别。我在本地 linux 机器或本地 Macintosh 上都有相同的延迟 sshing。我从 linode 到本地 linux 盒子的 sshing 没有这样的延迟。我有另一个使用相同版本 Debian 的远程系统,我可以在 2 秒内通过 ssh 连接到它。两个 Debian 机器上的文件之间的唯一区别/etc/ssh/sshd_config是快速的不允许密码,并且还指定了允许的密码列表。

如果我使用 登录ssh -vvv root@linode,则延迟发生在标有 >>>>>> 的部分

debug2: key: /root/.ssh/id_ecdsa ((nil))
debug2: key: /root/.ssh/id_ed25519 ((nil))
debug3: send packet: type 5
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50

>>>>>>

debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug3: send_pubkey_test

(这只是部分日志 - 可根据要求提供完整日志)

我找不到有关登录/var/log/auth.log/var/log/syslog延迟时间内的任何信息 - 之后我就得到了

Jul 27 13:46:43 linode sshd[23049]: Accepted publickey for root from 199.241.27.237 port 51464 ssh2: RSA 89:08:ef:44:48:a4:84:b7:0a:de:14:65:1b:d9:86:f8
Jul 27 13:46:43 linode sshd[23049]: pam_unix(sshd:session): session opened for user root by (uid=0)
Jul 27 13:46:43 linode systemd-logind[3235]: New session 10361 of user root.

答案1

如果创建连接很慢,但创建后速度正常,则很可能会遇到服务器正在为客户端进行反向 DNS 查找并且由于某种原因失败的问题。

一般情况下,调试这个的时候,也可以尝试从两个终端登录。第一次登录时请查看sshd服务器上的日志,而您尝试从第二次登录时查看服务器上的日志。这为您提供了有关服务器正在做什么(或正在等待)的更多信息。

您可以尝试通过在 中设置以下一项或两项来查找反向 DNS 查找原因的证据/etc/ssh/sshd_config

UseDNS no
UsePAM no

看看这是否可以加快创建连接的速度。如果确实如此,您通常可以保持这种状态直到解决(如果您关心这一点)。

如果这是反向 DNS 查找问题,则取决于您登录的计算机正在使用的 DNS 服务器。根据维基百科并非所有 IP 地址都有反向条目,因为这不是实际的标准要求。但更可能的是,这是一些配置问题。

答案2

在 Debian / Ubuntu 系统上,诀窍是从系统中踢出“avahi-daemon”,问题就消失了。

apt-get -y purge avahi*

相关内容