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 moment when your laptop goes to sleep or the coffee shop Wi-Fi dies and your SSH session just freezes in limbo? You’re left spamming enter for a minute before the client finally gives up and lets you reconnect.
💡 The Fix
Crank up the ServerAliveInterval to force the client to ping the host periodically. It makes the connection drop much faster when the network actually dies so you aren’t waiting on a dead socket.
ssh -o ServerAliveInterval=15 -o ServerAliveCountMax=3 user@hostname
⚙️ Why It Works
Adding these options tells your SSH client to send a null packet to the server every 15 seconds, and if it misses three in a row, it kills the session instantly instead of waiting for a TCP timeout.
🚀 Pro-Tip: Put these in your ~/.ssh/config file under a Host * block so you never have to type it again.
Linux Tips & Tricks | © ngelinux.com | 8/16/2026
