FG
💻 Software

How to reliably keep an SSH tunnel open?

Fresh5 days ago
Mar 15, 2026314577 views
Confidence Score1%
1%

Problem

I use an SSH tunnel from work to go around various idotic firewalls (it's ok with my boss :)). The problem is, after a while the ssh connection usually hangs, and the tunnel is broken. If I could at least monitor the tunnel automatically, I could restart the tunnel when it hangs, but I haven't even figured a way of doing that. Bonus points for the one who can tell me how to prevent my ssh connection from hanging, of course!

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: How to reliably keep an SSH tunnel open?

Low Risk

Sounds like you need autossh. This will monitor an ssh tunnel and restart it as needed. We've used it for a couple of years and it seems to work well. More details on the -M parameter here

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment