While working on a Ubuntu Linux laptop, I found my SSH sessions to a Linux server were being dropped after a few minutes when I switched to other tasks on the laptop. Using the
ServerAliveIntervalparameter when establishing the SSH connection allowed me to alleviate the problem of idle connections being dropped. E.g., I could use:
$ ssh -o ServerAliveInterval=5 -o ServerAliveCountMax=1 firstname.lastname@example.org
ServerAliveInterval to 5 will send a "heartbeat" signal
to the server every 5 seconds to keep the connection alive. Setting
ServerAliveCountMax to 1 means that when the time comes to send
another keepalive signal, if a response to the last one wasn't received, then
the connection will be terminated.
TCPKeepAlive setting could also be used, but, if there
is an intervening firewall it might be configured to drop the empty TCP ACK
packets that would be sent. The
sends data through the SSH connection, so from the perspective of the firewall
the packets are the same as any other encrypted packet.
How does tcp-keepalive work in ssh?
Date: March 12, 2012
Unix & Linux Stack Exchange
Keeping Your SSH Sessions Alive Through Pesky NAT Firewalls
Date: June 3, 2005
Steve Kehlet's Pages