Site icon New Generation Enterprise Linux

Stop letting your SSH session hang forever when a connection dies

SSH & Remote Administration

Stop letting your SSH session hang forever when a connection dies

🧩 The Challenge

Everyone has had their SSH terminal freeze mid-sentence because the laptop went to sleep or the coffee shop wifi choked. You end up sitting there hitting Ctrl+C for an eternity while the dead session refuses to drop.

💡 The Fix

You need to tell your client to actively check in on the server so it realizes the connection is toast before you get stuck in limbo. Just add a couple of heartbeat settings to your SSH config file.

Host *
ServerAliveInterval 30
ServerAliveCountMax 3

⚙️ Why It Works

Setting an interval forces the client to send a null packet every thirty seconds, and the count max defines how many failures to ignore before giving up. It effectively turns a zombie session into a disconnected one within 90 seconds.

🚀 Pro-Tip: Add these to your ~/.ssh/config and you’ll never have to kill a frozen shell manually again.

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

0 0 votes
Article Rating
Exit mobile version