Stop SSH connections from hanging when your laptop goes to sleep

SSH & Remote Administration

Stop SSH connections from hanging when your laptop goes to sleep

🧩 The Challenge

You know that feeling when you close your laptop, open it back up ten minutes later, and your terminal is just frozen dead? I’ve lost count of how many times I’ve had to kill a hanging session because the TCP connection died while I was away.

💡 The Fix

Just tell your SSH client to send a heartbeat signal every minute so the connection doesn’t go stale. It keeps the pipe active even if the network is flaky.

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

⚙️ Why It Works

Setting this makes your client proactively ping the server, preventing firewalls or routers from dropping the connection during idle periods. It effectively makes your connection significantly more resilient to power management glitches.

🚀 Pro-Tip: Add ServerAliveCountMax 3 to force a hard drop after three missed pings if the server actually goes dark.

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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted