SSH 随机连接超时

SSH 随机连接超时

我在尝试通过 SSH 连接服务器时遇到了一个奇怪的问题。超过 80% 的时间我都会遇到连接超时的情况,但有时也能成功连接。

我在路由器后面,所以办公室里的每个人都有相同的外部 IP,但不知何故我遇到很多连接超时,但其中一位运行 Windows + Putty 的同事没有遇到这个问题。

例子:

user@user-HP-Pavilion-Gaming-Notebook ~ $ date; ssh -vvv [email protected]

Wed Mar 15 12:58:53 CET 2017
OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "srv.domain.com" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to srv.domain.com [122.55.66.77] port 22.
debug1: connect to address 122.55.66.77 port 22: Connection timed out
ssh: connect to host srv.domain.com port 22: Connection timed out





user@user-HP-Pavilion-Gaming-Notebook ~ $ date; ssh -vvv [email protected]

Wed Mar 15 12:58:59 CET 2017
OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "srv.domain.com" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to srv.domain.com [122.55.66.77] port 22.
debug1: connect to address 122.55.66.77 port 22: Connection timed out
ssh: connect to host srv.domain.com port 22: Connection timed out



user@user-HP-Pavilion-Gaming-Notebook ~ $ date; ssh -vvv [email protected]

Wed Mar 15 12:59:03 CET 2017
OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "srv.domain.com" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to srv.domain.com [122.55.66.77] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.7p1 Debian-5+deb8u3
debug1: match: OpenSSH_6.7p1 Debian-5+deb8u3 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to srv.domain.com:22 as 'root'
debug3: hostkeys_foreach: reading file "/home/user/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /home/user/.ssh/known_hosts:12
debug3: load_hostkeys: loaded 1 keys from srv.domain.com
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent

我还尝试检查 /var/log/auth.log 中是否有有关该问题的信息,但是当我尝试连接时我看不到任何内容并且超时了。

服务器对 ping 的响应很好,但是我也尝试通过 telnet 连接到端口 22,并且同样超时。

有任何想法吗?

我正在运行 Linux Mint,服务器采用 Debian Jessie。

答案1

我正面临同样的问题。

但事实证明我的 RSA 密钥才是罪魁祸首。我使用的是密钥长度为 4096 位的 RSA。将我的私钥更改为 ed25519 后,我再也没有遇到这个问题。

答案2

可能是 DNS 问题。尝试在 ssh 服务器中禁用 DNS 解析。

# /etc/ssh/sshd_config
UseDNS no

相关内容