Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 7 down vote accepted

When you start autossh without -f, you get a shell. While the shell is working, you get port forwarding. After you logout, ssh terminstes 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
share|improve this answer
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 '14 at 15:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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