Stop your SSH sessions from hanging on bad wifi

SSH & Remote Administration

Stop your SSH sessions from hanging on bad wifi

🧩 The Challenge

You know that feeling when your laptop goes to sleep or you switch from Wi-Fi to a cellular hotspot and your SSH sessions just freeze indefinitely? It’s infuriating to wait for the TCP timeout while your terminal stays locked in a dead connection.

💡 The Fix

Tell your SSH client to send heartbeats periodically so it actually realizes the pipe is dead and kicks you out instead of hanging. This way you can reconnect immediately without waiting ten minutes for the kernel to give up.

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

⚙️ Why It Works

Setting this value forces the client to ping the server every 15 seconds; if the server doesn’t respond, SSH drops the connection cleanly instead of leaving your process in limbo. It effectively kills off those “zombie” sessions that refuse to die.

🚀 Pro-Tip: Add ServerAliveCountMax 3 to the same file if you want to be extra sure about the threshold before the connection drops.

Linux Tips & Tricks | © ngelinux.com | 10/10/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted