job.answiz.com
  • 1
Votes
name
name Punditsdkoslkdosdkoskdo

How to dependably keep a SSH burrow open?

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!

You need to specify amount of the tries and interval of sending a packet to the server. You can put the following lines in your .ssh/config file:

Host examplehost
    Hostname examplehost.com
    ServerAliveInterval 180
    ServerAliveCountMax 2

This will send a packet to the server every 180 seconds (3 minutes) and it will try two times before it closes the connection after getting no response from the client.

  • 0
Reply Report

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.

autossh -M 20000 -f -N your_public_server -R 1234:localhost:22 -C

More details on the -M parameter here

  • 0
Reply Report