1

I would like to launch a ssh reverse tunnel on system launch. The following line let's me establish the tunnel fine - but I end up being logged into server which I don't want, especially not from an init script.

/usr/bin/autossh -M 22222 -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /path/to/my/key.key -R 9999:localhost:22 ubuntu@server

man autossh says that the -f option should do what I need:

causes autossh to drop to the background before running ssh.

but the problem is, it doesn't seem to work when I change my command to usr/bin/autossh -f -M.... I've tried this out as part of my init script too which looks like:

#! /bin/sh
### BEGIN INIT INFO
### END INIT INFO
case "$1" in
    start)
        echo "Starting autossh"
        /usr/bin/autossh -M 22222 -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /path/to/the.key -R pppp:localhost:22 user@server
    ;;
    stop)
        echo -n "Shutting down utossk"
        /usr/bin/killall -KILL autossh
    ;;
    *)
        echo "Usage: $0 {start|stop}"
        exit 1
esac
exit 0

But I need an option to throw it in the background, how do I do this if the -f option doesn't work for me?

0

1 Answer 1

1

What you're looking for is the -N option. From SSH's man page:

-N Do not execute a remote command. This is useful for just for‐ warding ports.

Your full command would be:

/usr/bin/autossh -M 22222 -f -N -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /path/to/my/key.key -R pppp:localhost:22 user@server

Which is also what I am using (with cron's @reboot), with success.
Replace pppp: with the local port you'd like to use.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .