DEV Community

Ramiro Gómez
Ramiro Gómez

Posted on • Originally published at geeksta.net on

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

Enter fullscreen mode Exit fullscreen mode

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

Host *
    ServerAliveInterval 60
    ServerAliveCountMax 3

Enter fullscreen mode Exit fullscreen mode

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.


Thank you for reading!

This article was written by Ramiro Gómez using open source software and the assistance of AI tools. While I strive to ensure accurate information, please verify any details independently before taking action. For more articles, visit the Geeklog on geeksta.net.

Top comments (0)