autossh not working in background

3

1

I am trying to setup autossh to run a tunnel to my VPN server. If I use autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -R 10000:localhost:22 console@<myvpnip>, it seems to work well and I can use the tunnel.

However, if I add a -f flag to run in the background, autossh -f -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -R 10000:localhost:22 console@<myvpnip>, I get Connection refused when trying to use the tunnel.

What is going on here? Is there a way to log any errors while running it in the background?

ericksonla

Posted 2017-12-19T20:42:54.553

Reputation: 235

Answers

3

Were you able to enter the password when you used the -f flag? From the autossh man page:

Note that there is a crucial a difference between -f with autossh, and -f with ssh: when used with autossh ssh will be unable to ask for passwords or passphrases

You can still use the -f flag, but then you can't use password authentication. Instead use public key authentication with an authorized_keys-file on the VPN server. Then it should work with autossh -f -M 0 -N -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -R 10000:localhost:22 console@<myvpnip>. Note the extra -N option to ssh, useful for just forwarding ports.

You should be able to see debug info with tail -f /var/log/syslog or with journalctl -f.

tuntap

Posted 2017-12-19T20:42:54.553

Reputation: 156

I already had the password turned off and the auth keys turned on, but thats a good thought. The syslog is a good resource though, thanks! – ericksonla – 2017-12-19T23:35:17.847

2

Turns out I needed some more flags. I think the problem was that I needed to suppress some unwanted return data (like giving me a command line). It worked well with this:

autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -fN -T -R 10000:localhost:22 console@<myvpnip>

ericksonla

Posted 2017-12-19T20:42:54.553

Reputation: 235