SSH Keep connection alive
Add below lines to file ~/.ssh/config
Host * ServerAliveCountMax 3 ServerAliveInterval 10 TCPKeepAlive yes
The first line specifies that this applies to all hosts
The second and third specify that SSH2 keepalive messages should be sent every 10 seconds during periods of inactivity, and to consider the connection dead after 3 non-responses to those messages.
The last line enables TCP transport-layer keepalive messages (which were the only keepalive method available in SSH1, but itĀ isn’t quite enough in SSH2).