Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I frequently use ssh tunnels to access VNC sessions on remote machines, but this is on my laptop so the connections break when I put it to sleep for the night. If I then try to re-open the connection in the morning, I have to manually kill the ssh session, otherwise I get this error:

bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 1202
Could not request local forwarding.

The SSH command I'm using is this:

ssh -N -C -f -L 1202:localhost:5900 name@server

What's the best way to have the ssh tunnel die when it disconnects? Or reset?

share|improve this question

For automatic restarting of an ssh session, try using autossh

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .