Kill ssh background process after disconnect / timeout?
- by keflavich
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?