Stop your SSH session from hanging when you switch networks

SSH & Remote Administration

Stop your SSH session from hanging when you switch networks

🧩 The Challenge

Everyone knows the pain of closing a laptop lid on a coffee shop Wi-Fi and opening it at home, only for your terminal to sit there frozen like a statue. You end up hitting Ctrl-C like a maniac, but the session is already dead.

💡 The Fix

You can force SSH to send keep-alive packets periodically to see if the connection is actually still there. It makes your terminal realize it’s disconnected way faster so you can just reconnect and get back to work.

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

⚙️ Why It Works

Setting this interval sends a null packet to the server every fifteen seconds, effectively waking up the TCP stack or noticing when the path is totally gone. If the server doesn’t respond after a few tries, your client drops the connection cleanly instead of hanging.

🚀 Pro-Tip: Add ServerAliveCountMax 3 to your config if you want it to be even more aggressive.

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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted