Stop SSH from hanging forever when the network drops

SSH & Remote Administration

Stop SSH from hanging forever when the network drops

🧩 The Challenge

You know that feeling when your laptop goes to sleep or the Wi-Fi blips and your SSH session just sits there like a zombie? It’s infuriating when you try to kill the terminal but it refuses to budge.

💡 The Fix

Just configure the client to send heartbeats automatically so it knows the connection is dead before you do. Adding these few lines to your config saves you from endless session timeouts and frozen shells.

echo "ServerAliveInterval 15" >> ~/.ssh/config
echo "ServerAliveCountMax 3" >> ~/.ssh/config

⚙️ Why It Works

By sending a null packet every fifteen seconds, the client realizes the connection is gone if it misses three in a row. It kills the socket cleanly so you can get back to work immediately.

🚀 Pro-Tip: Use the -o flag if you just want to test this once without messing with your global config file.

Linux Tips & Tricks | © ngelinux.com | 8/4/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted