DEV Community

Ramiro Gómez
Ramiro Gómez

Posted on • Originally published at geeksta.net on

5

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.

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!

Join the Runner H "AI Agent Prompting" Challenge: $10,000 in Prizes for 20 Winners!

Runner H is the AI agent you can delegate all your boring and repetitive tasks to - an autonomous agent that can use any tools you give it and complete full tasks from a single prompt.

Check out the challenge

DEV is bringing live events to the community. Dismiss if you're not interested. ❤️