5

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 the following when trying to use the tunnel.

Connection refused

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

2 Answers 2

4

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.

1
  • 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
    Commented Dec 19, 2017 at 23:35
4

It 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>
1
  • Thank you. Based on this answer the following worked for me: autossh -fN -T -R ...
    – amit
    Commented Sep 4, 2022 at 11:38

You must log in to answer this question.

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