How to keep SSH connections "alive"

If you're a regular SSH user, you've probably noticed that it sometimes "disconnects itself." To correct this, you just have to get your hands "a bit dirty" and change some configuration files.

To do this, you have to change the values ​​assigned to 2 variables ServerAliveCountMax and ServerAliveInterval.

ServerAliveCountMax sets the number of "server is alive" messages that can be sent without ssh receiving a response from the server. This type of message is essential to know if the connection is still active or not (perhaps the server "went down", etc.).

ServerAliveInterval sets the interval (in seconds) after which, in case of no response from the server, ssh will resend a message requesting a response.

On the client

For the changes to have effects for all users, the file must be modified  / Etc / ssh / ssh_config. On the other hand, if you want the changes to only take effect for your user, modify the file ~ / .ssh / config.

Add the following in the SSH configuration file:

    ServerAlive Interval 300
    ServerAliveCountMax 3

On the server

In order for the server to keep the connections with all clients alive, add the following in the file / Etc / ssh / sshd_config:

ServerAlive Interval 300
ServerAliveCountMax 3

This configuration causes the client / server to send a message to the counterpart every 300 seconds (5 minutes) and to give up at the 3rd opportunity if it has not received any response.

The content of the article adheres to our principles of editorial ethics. To report an error click here!.

3 comments, leave yours

Leave a Comment

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



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Algave said

    Very good even that in Archlinux we edit the same file / etc / ssh / sshd_config and uncomment (remove the #) ClientAliveInterval and change the value from 0 to 300, we also uncomment ClientAliveCountMax and leave the default value that is 3 (this for Client ).

  2.   ermimetal said

    Thank you very much for the information, with this I will save a lot of work.