Stop your SSH sessions from hanging when the network dies

SSH & Remote Administration

Stop your SSH sessions from hanging when the network dies

🧩 The Challenge

Everyone has been there: you are in the middle of a delicate file edit or a database dump over a shaky Wi-Fi connection, and then the screen just freezes. You wait, mash the keyboard, and eventually realize the connection is dead, but your terminal is still stuck waiting for a response that will never come.

💡 The Fix

You need to tell your SSH client to periodically check in with the server so it knows exactly when the connection has kicked the bucket. Adding a keepalive setting to your config stops those “zombie” sessions that refuse to time out.

Host *
ServerAliveInterval 15
ServerAliveCountMax 3

⚙️ Why It Works

By setting the interval to 15 seconds, your client sends a null packet to the server if there’s no activity. If the server misses three of those in a row, the client kills the session instantly instead of letting it hang indefinitely.

🚀 Pro-Tip: Put these in your ~/.ssh/config so you never have to remember to type them out for new servers.

Linux Tips & Tricks | © ngelinux.com | 7/25/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted