尝试连接某些主机时 ssh 冻结

尝试连接某些主机时 ssh 冻结

当我尝试 ssh 到列表中的特定机器时,SSH 命令恰好冻结。我尝试设置 ssh 超时。但即使在超时后它也会冻结。

在详细模式下:

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 x358.x.server.com [10.x.x.x] port 22.
debug1: fd 3 clearing O_NONBLOCK
debug1: Connection established.
debug1: identity file /export/home/sqlrpt/.ssh/identity type -1
debug1: identity file /export/home/sqlrpt/.ssh/id_rsa type -1
debug1: identity file /export/home/sqlrpt/.ssh/id_dsa type 2

此时它会冻结。

我认为一种解决方法是为每个 ssh 调用创建一个子进程,如果该进程在超时后没有响应 - 则终止它。但是有没有更简单的方法,以便我可以将其容纳在 shell 脚本本身中,而不是使用 C/C++ 程序?

答案1

ssh -2 -o ConnectTimeout=5

这招奏效了。它不再卡住了

答案2

你可能发现了这个错误https://bugzilla.redhat.com/show_bug.cgi?id=143316
它在这里被重复了https://bugzilla.redhat.com/show_bug.cgi?id=133884,并且有一个解决方法

echo 0 > /proc/sys/net/ipv4/tcp_default_win_scale

答案3

我在使用 openSuse 11.4 (x86_64) (内核 2.6.37.6-24-desktop),SSH 版本:OpenSSH_5.8p1,OpenSSL 1.0.0c 2 Dec 2010 时也遇到了同样恼人的问题。

echo 0 > /proc/sys/net/ipv4/tcp_window_scaling

采取了这个办法,问题就解决了。

答案4

我认为问题出在主机的互联网上。这种情况已经发生过几次了。在 ssh 之前关闭主机的互联网然后再打开。

相关内容