解决 SSH 登录报错 kex_exchange_identification: banner line exchange timed out
分析 SSH 握手报 banner line exchange timed out 诱因,详解 sshd 并发限制与网络高延迟超时调优。
问题现象
在网络抖动或高并发场景下通过 SSH 连接远程主机时,连接等待数十秒后崩溃:
kex_exchange_identification: banner line exchange timed out
fatal: Could not read from remote repository.
触发根因
客户端与服务端在建立加密通信前,必须首先交换协议版本号字符串(SSH Banner)。在跨国跨网链路下,网络握手延迟超过了客户端预设的超时限制,或者服务端 sshd 在反查客户端 DNS(UseDNS)时发生长耗时阻塞。
解决方案
方案一:在服务端 sshd_config 中禁用 UseDNS
编辑 /etc/ssh/sshd_config:
UseDNS no
GSSAPIAuthentication no
重启 sshd 服务:sudo systemctl restart sshd。
方案二:调大客户端连接与握手超时时限
在客户端 ~/.ssh/config 中配置:
Host *
ServerAliveInterval 15
ServerAliveCountMax 3
TCPKeepAlive yes
验证方法
再次发起 SSH 登录,秒级完成握手进入命令行。


