我认为这个问题有一个简单的答案,但我在网上找到的一切都是关于防止SSH客户端连接超时的。
在这种情况下,客户端已经建立了到服务器的连接,并保持了连接。然后连接中断,例如以太网电缆断开,或者路由器关闭。
当发生这种情况时,客户端连接不会被删除。
ssh客户端连接是脚本的一部分,执行ssh登录的行如下所示:
ssh -Nn script@example.com
. .ssh/config包含以下参数:
Host *
ServerAliveInterval 60
ServerAliveCountMax 2当出现这些断开时,我希望客户端ssh连接超时,并允许脚本尝试重新连接.
谢谢!
发布于 2022-06-12 00:14:15
我想我错了,这是一个简单的问题,因为没有人能够提供一个答案。
我的进一步阅读和询问导致了一个答复在开放的IRC频道,大约2022-06-06。我被告知,备选方案:
ServerAliveInterval 60
ServerAliveCountMax 2通常不要像人们所期望的那样断开客户端的连接。
ssh_config手册页:
ServerAliveCountMax
Sets the number of server alive messages (see below) which
may be sent without ssh(1) receiving any messages back from
the server. If this threshold is reached while server alive
messages are being sent, ssh will disconnect from the server,
terminating the session...
The default value is 3. If, for example, ServerAliveInterval
(see below) is set to 15 and ServerAliveCountMax is left at
the default, if the server becomes unresponsive, ssh will
disconnect after approximately 45 seconds.似乎完全可以肯定地说,由于缺少服务器响应而断开连接是这些参数的意图。然而,在实践中,这并不是在所有情况下都发生的。也许这里的警告是:“当服务器活着的消息被发送时”?
如果应用程序在服务器没有响应时调用可靠的客户端断开连接,则建议实现与ssh客户端登录脚本分离的外部方法,该方法监视服务器响应,并在超时时终止ssh客户端进程。
https://stackoverflow.com/questions/72492385
复制相似问题