Stable remote port fowarding
-
This is because the host you’re connecting to may not realize that the previous connection has died, and is still utilizing the port. While the new autossh connection will succeed, it won’t open a tunnel and autossh won't restart since it thinks the connection is okay.
-
There are two particular OpenSSH options that are useful when using autossh:
-
ExitOnForwardFailure=yes on the client side to make sure forwardings have succeeded when autossh assumes the connection is set up properly.
-
ClientAliveInterval on the server side to make sure the listening socket is closed on the server side if the connection closes on the client side.
Replace the autossh command for:
-o “ServerAliveCountMax 3” with -o “ServerAliveCountMax=3”
-o “ServerAliveInterval 60” with -o “ServerAliveInterval =60”
the “=” sign was critical
-
Example:
autossh -M 0 -q -f -gNC -o “ServerAliveCountMax=3” -o “ServerAliveInterval=60” -o “ExitOnForwardFailure=yes” -R xxxx:localhost:22 auto ssh@remotehost