Kill ssh background process after disconnect / timeout?

Posted by keflavich on Super User See other posts from Super User or by keflavich
Published on 2012-12-13T15:05:42Z Indexed on 2012/12/13 17:06 UTC
Read the original article Hit count: 260

Filed under:
|

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?

© Super User or respective owner

Related posts about ssh

Related posts about port-forwarding