autossh and port not available

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

I am trying to open a ssh reverese connection from computer A to B using

I run the command
autossh -f -M 0 -N -R 8022:localhost:22
(where of course I have the actual address instead of
On A I have
ServerAliveInterval 10
ServerAliveCountMax 10
in /etc/ssh/ssh_config

I am having trouble however in that  machine A shuts down and then started
up, autossh is run I get

 error: channel_setup_fwd_listener: cannot listen to port: 8022

on B. I suspect that B does not know that A has gone down, and still thinks
that ssh is listening on 8022 to forward the connection.

How do I handle this? Ie how do I make sure B thinks that the connection
has died when A goes down?

This also happens sometimes when the cordless phone near A interferes with
the wireless and effectively cuts off the wireless for a while. Then when A
autossh restarts ssh, B thinks that there is still a connection to 8022 and
does not allow the forwarding.
Of course eventually B drops the original sshd but since autossh has an
open ssh connection ( even if it is not attached to the port) it never
Or does the ServerAlive really not work, and I should use the ports things
so that autossh knows that the port forwarding is not working.

Site Timeline