7

I would love to set autossh to run at boot adding it to /etc/rc.local.

This command works:

autossh -i /root/.ssh/id_rsa -R 2522:localhost:22 user@address

But, if I add the -f option

autossh -f -i /root/.ssh/id_rsa -R 2522:localhost:22 user@address

The ssh session is not started.

As you can see, I'm using an absolute path for my identity file, so this seems to be a different problem from the one stated here: autossh in background does not work

From /var/log/syslog:

Oct 18 11:08:39 raspberrypi autossh[2417]: starting ssh (count 1)
Oct 18 11:08:39 raspberrypi autossh[2417]: ssh child pid is 2418
Oct 18 11:08:39 raspberrypi autossh[2417]: ssh exited with status 0; autossh exiting

I'm using it with debian wheezy on a raspberry pi, autossh version 1.4c.

Could it be that it's passing the -f option to ssh instead?

1 Answer 1

15

When you start autossh without -f, you get a shell. While the shell is working, you get port forwarding. After you logout, ssh terminates with exit code 0 and autossh knows it does not need to launch ssh session again.

When you start autossh with -f, it passes -f to ssh too. ssh is then running in the background and does not give you a shell. As you did not specify any other flags or remote command, ssh exits immediately with status 0 (nothing to do), and autossh does not start it over.

Just add -N option to avoid it:

-N      Do not execute a remote command.  This is useful for just forwarding
        ports (protocol version 2 only)

Like this:

autossh -f -N -i /root/.ssh/id_rsa -R 2522:localhost:22 user@address
1
  • 4
    This seems to work, but contradicts what the man page says: -f causes autossh to drop to the background before running ssh. The -f flag is stripped from arguments passed to ssh.
    – Jay K
    Mar 7, 2014 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.