Contents
What is SSH ServerAliveInterval?
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.
How does SSH keepalive work?
The KEEPALIVE option of the TCP/IP Protocol ensures that connections are kept alive even while they are idle. When a connection to a client is inactive for a period of time (the timeout period), the operating system sends KEEPALIVE packets at regular intervals.
What is the value of serveraliveinterval in SSH?
ClientAliveInterval: number of seconds that the serverwill wait before sending a null packet to the client (to keep the connection alive). Setting a value of 0 (the default) will disable these features so your connection could drop if it is idle for too long. ServerAliveInterval seems to be the most common strategy to keep a connection alive.
How to prevent ssh disconnects with serveraliveinterval?
Some firewalls or NAT gateways can be more aggressive than TCP timers or some TCP stacks can be more relaxed in terms of TCP keepalives and, in these cases, the TCP sessions could be cleared leaving SSH session to hang while the client sends commands to the server and waits for ACK tcp packets, thus becoming unresponsive.
What’s the best way to keep SSH connection alive?
ServerAliveInterval seems to be the most common strategy to keep a connection alive. To prevent the broken pipe problem, here is the ssh config I use in my .ssh/config file: The client will wait idle for 60 seconds (ServerAliveInterval time) and, send a “no-op null packet” to the server and expect a response.
When to disconnect from a SSH connection?
The server alive mechanism is valuable when the client or server depend on knowing when a connection 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.