Stop your SSH tunnels from hanging dead in the background

SSH & Remote Administration

Stop your SSH tunnels from hanging dead in the background

🧩 The Challenge

You open a tunnel to a database on a remote machine, get distracted by an urgent ticket, and come back to find your connection is a zombie process that refuses to die or forward a single packet. It’s infuriating to realize you’ve been shouting at a silent screen for twenty minutes while your session sat there in a comatose state.

💡 The Fix

Tell your SSH client to periodically send a heartbeat signal through the encrypted tunnel to verify the connection is still alive. By configuring the server to send these pulses, you’ll force the connection to drop gracefully instead of hanging your terminal whenever the network hiccups.

Host *
ServerAliveInterval 60
ServerAliveCountMax 3

⚙️ Why It Works

Setting these options in your config file forces the SSH client to ping the server every sixty seconds, and if it misses three heartbeats in a row, it kills the connection automatically. This prevents your shell from sitting there spinning indefinitely while waiting for a response that will never arrive.

🚀 Pro-Tip: Toss these lines into your ~/.ssh/config once and you’ll never have to manually kill a stuck port forward again.

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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted