How to Keep Alive SSH Sessions
Translations
Abstract
Many NAT firewalls time out idle sessions after a certain period of time to keep their trunks clean.
There are two options:
- We can tell the SSH client to send keepalive packets to the server
- We can make the SSH server keep alive all connections with its clients
The settings below will make the SSH client or server send a null packet to the other side every 300 seconds (5 minutes), and give up if it doesn’t receive any response after 2 tries, at which point the connection is likely to have been discarded anyway.
Clientsetting
PuTTY
In your session properties, go to Connection
and under Sending of null
packets to keep session active
, set Seconds between keepalives (0 to
turn off)
to e.g. 300 (5 minutes).
OpenSSH
To enable the keep alive system-wide, edit /etc/ssh/ssh_config
To set the settings for a user only, edit ~/.ssh/config
Insert the following in the appropriate file:
Host *
ServerAliveInterval 300
ServerAliveCountMax 2
Serverseting
OpenSSH
Add to the file /etc/ssh/sshd_config
:
ClientAliveInterval 300
ClientAliveCountMax 2