Unable to use autossh in background even with absolute path
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?
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