Published : 2017-04-04

Connection keepalive

We usually have several terminals connected via SSH to different machines, and some of them may stay idle for several dozens of minutes or even hours. In some network configurations, application firewalls tend to drop the state of a connection if it has been inactive for some time, causing TCP PUSHes to be blocked, despite a CONNECTED state on the client side.

OpenSSH has a very handy option to perform a NOOP (non-operation) that “refreshes” the state of the TCP connection on the firewalls the connection goes through.

Edit the /etc/ssh/ssh_config or ~/.ssh/config file and simply add the following line:

ServerAliveInterval 60

Here we tell SSH to send a NOOP every minute.

It is also possible to apply this change only to some hosts using the Host directive:

Host unix-experience.fr
ServerAliveInterval 60

Note: this does not apply to already active sessions.