SSH中的ServerAliveCountMax

SSH中的ServerAliveCountMax实际上是做什么的?

我试图确保当我通过SSH连接到我的服务器时,连接长时间保持打开状态,而不是在短时间不活动后连接死机。 这是例子

Host * ServerAliveInterval 60 ServerAliveCountMax 2 

我从一个消息来源获悉,只要服务器收到响应,上面的设置就会每隔60秒向服务器发送一个响应。 但是,如果由于某种原因,响应不通过服务器,它会尝试发送另一个消息。 如果该消息也失败,则会closures连接。 (我觉得这是错误的)

然而第二和第三来源却说了一些不同的东西。 他们声称,如果有一段时间不活动,则会每60秒向服务器发送一条消息,但只会发送2个请求,然后closures连接。

那么ServerAliveCountMax究竟做了什么?

你的感觉是“这是错的”是正确的。 见手册页 :

  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. It is important to note that the use of server alive messages is very different from TCPKeepAlive (below). The server alive messages are sent through the encrypted channel and there‐ fore will not be spoofable. The TCP keepalive option enabled by TCPKeepAlive is spoofable. The server alive mechanism is valu‐ able when the client or server depend on knowing when a connec‐ tion has become inactive. 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. This option applies to protocol version 2 only. ServerAliveInterval Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server. This option applies to protocol version 2 only.