Search code examples
autossh

autossh tunnel getting killed after 10 minutes


I have an autossh tunnel set up over which I am sending something that needs an uninterrupted connection for a couple dozen minutes. However, I noticed that every 10 minutes the SSH tunnel managed by autossh is killed and recreated.

This is not due to an inactive connection, as there is active communication happening through that channel.

The command used to set up the tunnel was:

autossh -C -f -M 9910 -N -L 6969:127.0.0.1:12345 remoteuser@example.com

Solution

  • In my case the problem was a clash of the monitoring ports on the remote server. There are multiple servers all autossh-ing to the single central server and two of those "clients" used the same monitoring port (-M).

    The default interval in which autossh tries to communicate over the monitoring channel is 600 seconds, 10 minutes. When autossh starts up, it does not verify that it could open the remote monitoring port. Everything will look fine until the time when autossh tries to check that the connection is open - and it fails. At that point the SSH tunnel will be forcibly killed and recreated.

    A good way to check if this is your case as well is change the default timeout using the AUTOSSH_POLL environment variable:

    AUTOSSH_POLL=10 autossh -C -f -M 9910 -N -L 6969:127.0.0.1:12345 remoteuser@example.com