SSH Keepalive

Isn’t it frustrating when You start up a SSH session and it times out. Usually at the worst possible moment.
Using screen is good, but it comes to ones mind always after that dreadful timeout.

OpenSSH supports a thng called keepalive – a keepalive packet is sent after a predetermined interval of inactivity so SSH sessions should not time out.

Keepalive can be set on server side or client side.

Client side is usually better because then all possible connections are kept alive.

Client side:
and enable
ServerAliveInterval 30
30 is as good as 25 or 54 or 41 but 30 sounds best to me 🙂

or if You can not edit global config file put the same line in Your personal config file:

Server side:
and enable
ClientAliveCountMax 10
ClientAliveInterval 30

This means that after 30 seconds of inactivity server sends a keepalive message.
After 10 messages without responses from client connection is dropped.

This is different from TCPKeepAlive, as manual says:

If they are sent, death of the connection or crash of one of the machines will be properly noticed. However, this means that connections will die if the route is down temporarily, and some people find it annoying.

Actually TCPKeepAlive is on by default but I still get disconnects from some servers behind some firewall or DSL device. Go figure.

Leave a comment

Your email address will not be published. Required fields are marked *