Prevent SSH connection from timing out

In case you are plagued by SSH connections dying in the worst moments and the following waiting period, here might be the solution to your problem.

Solution on your server

In /etc/ssh/sshd_config change or add the following lines:

ClientAliveInterval 30
ClientAliveCountMax 3

ClientAliveInterval will make your server ask the client whether it is still there and alive, every 30 seconds.
ClientAliveCountMax will try this 3 times if the client is not answering. After this 3 attempts, the server will close the connection.

Solution on your client

On the client it is basically the same. Only you have to replace “Client” with “Server”.

ServerAliveInterval 30
ServerAliveCountMax 3

To change these settings, update you ssh_profile with the entries.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.