System Administration

SSH keep-alive / timeout

By ayates.

If you find you're having a hard time keeping a connection, your SSH sessions are locking up or disconnecting after short periods of inactivity and it's driving you slightly insane you can set the SSH keep-alive interval in your .ssh/config:

Open or create your ssh/config file in your editor of choice e.g.

vi ~/.ssh/config

And add the following line to your file:

ServerAliveInterval 15

This indicates the number of seconds after which a message will be sent to the server to keep the connection alive, only if no data is received from the server in that period. The default value for this is 0 (never). Check the man page for more information.