Stop waiting for SSH to timeout when a remote box hangs
SSH & Remote Administration
Stop waiting for SSH to timeout when a remote box hangs
🧩 The Challenge
You’ve finally tracked that remote server issue down, only to have the box lock up mid-session. Now you’re left staring at a frozen cursor for thirty seconds while the SSH client tries to figure out if the server is ever coming back.
💡 The Fix
Throw some TCP keepalive options in your SSH config to kill dead sessions instantly. It saves you from staring at a dead terminal whenever a network link drops or a kernel panics.
Host *
ServerAliveInterval 15
ServerAliveCountMax 3
⚙️ Why It Works
By sending a null packet every 15 seconds, the client realizes the connection is toast much faster than the default TCP timeout. If it misses three replies, it kills the socket, letting you get back to work immediately.
🚀 Pro-Tip: Use ServerAliveCountMax 0 if you want to be even more aggressive about pruning stale connections.
Linux Tips & Tricks | © ngelinux.com | 11/15/2026
