One of the servers which I login to on a regular basis has the annoying habit of dropping any SSH connections where there has been no activity for more than 3 minutes. Having to repeatedly reconnect is frustrating, especially if I’m leaving a script running.
Fortunately, there’s a simple solution in the form of two configuration options:
ServerAliveInterval X: Request a response from the server if no data has been received for X seconds.
ServerAliveCountMax Y: Disconnect if more than Y requests have been sent to the server without receiving a response
If responses are not received from the server, the connection will be terminated automatically after X * Y seconds.