Stop SSH from hanging indefinitely when your remote connection drops
SSH & Remote Administration
Stop SSH from hanging indefinitely when your remote connection drops
🧩 The Challenge
You’ve been there, staring at a frozen terminal because your laptop went to sleep or the hotel Wi-Fi decided to take a permanent vacation. Watching the cursor blink while you try to force quit your local session is pure agony.
💡 The Fix
Tweak your SSH config to send keepalive packets at regular intervals. It forces the connection to die cleanly so your local shell doesn’t hang forever.
echo "ServerAliveInterval 60" >> ~/.ssh/config
echo "ServerAliveCountMax 3" >> ~/.ssh/config
⚙️ Why It Works
By sending a null packet every minute, the client realizes the pipe is broken and drops the connection rather than waiting for a TCP timeout that might never trigger. The count max defines how many failures to ignore before giving up.
🚀 Pro-Tip: Add these to your global /etc/ssh/ssh_config if you want the sanity for every user on the box.
Linux Tips & Tricks | © ngelinux.com | 7/30/2026
