How to Prevent SSH Timeout on Linux Systems

If you've ever experienced your SSH connection freezing due to inactivity, you're not alone. This common issue can be particularly frustrating, but fortunately, there's a simple solution. By adjusting your SSH client configuration, you can keep the connection alive. Follow these steps to prevent SSH timeout on your Linux machine.

Edit the SSH Configuration

First, you'll need to edit the SSH configuration file. If it doesn't already exist, create it. Start a terminal and open the file with your preferred editor, for example:

vim ~/.ssh/config

Next, add the following lines to ensure your SSH connection remains active:

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 3

Save the file and exit the text editor. For the changes to take effect, you need to restart your SSH connection.

Explanation

Here's what these settings do:

  • ServerAliveInterval 60: This sends a keep-alive packet to the server every 60 seconds.
  • ServerAliveCountMax 3: If the server does not respond after three keep-alive packets, the connection will be terminated.

That's it! Your SSH connection should now remain active even during periods of inactivity. Adjust the ServerAliveInterval value as needed to fit your specific requirements.

Conclusion

By following this short and simple guide, you can prevent your SSH connections from freezing due to inactivity. This small configuration change can save you from the hassle of repeatedly reconnecting to your remote servers.


This post was written by Ramiro Gómez (@yaph) and published on . Subscribe to the Geeksta RSS feed to be informed about new posts.

Tags: howto linux sysadmin

Disclosure: External links on this website may contain affiliate IDs, which means that I earn a commission if you make a purchase using these links. This allows me to offer hopefully valuable content for free while keeping this website sustainable. For more information, please see the disclosure section on the about page.


Share post: Facebook LinkedIn Reddit Twitter

Merchandise