0

I configured a reverse ssh tunnel through machines A (local, behind several routers) B (middlemen) and C (remote, the one I'm trying to access A from)

After putting all relevant keys on all machines, if I do

autossh -M 10984 -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no -i /home/user/.ssh/id_rsa.pub 9999:localhost:22 user@machine-B

on machine A, I can connect from machine C to machine B (middlemen) to A through port 9999.

Now, I added

autossh -M 10984 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no -i /home/user/.ssh/id_rsa.pub 9999:localhost:22 user@machine-B &

to my /etc/rc.local file, so the command would get executed at boot, rebooted, and now the tunneling won't work. I get an error

autossh[1966]: starting ssh (count 14)
autossh[1966]: ssh child pid is 4916
autossh[1966]: ssh exited with error status 255; restarting ssh 

on the syslog.

My /etc/rc.local has:

autossh -M 10984 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /home/user/.ssh/id_rsa.pub -R 9999:localhost:22 user@machine-B &
ethtool -s eth0 autoneg on
exit 0

Any idea what I might be doing wrong?

UPDATE: I noticed that while

autossh -M 10984 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /home/user/.ssh/id_rsa.pub -R 9999:localhost:22 user@machine-B

works on the command line, sudo-ing it:

sudo autossh -M 10984 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /home/user/.ssh/id_rsa.pub -R 9999:localhost:22 user@machine-B

makes the command line prompt me for the public key passphrase, even though it has no attached passphrase. I read on another Stack question (which I can't find) that the -f flag prevents ssh from asking for further input. As thigs on rc.local are run as root (as far as I know), I think that this is why it autossh keeps creating ssh process which exit unsuccessfully. Indeed, removing the -f flag makes ubuntu keep creating windows prompting me for the passphrase. I entered no passprase when creating the key.

  • using a non-interactive tty. The proper way is using (open)vpn. – Ipor Sircer Dec 19 '17 at 5:56
  • I think -n is supposed to be used when backgrounding ssh...does it help? Speaking of backgrounding you ought to get rid of the &. You don't need it if you use -f (side note: autossh handles -f instead of passing it to ssh but it does the same thing.). – B Layer Dec 19 '17 at 8:41
  • @BLayer I'm afraid I don't quite get what you're saying. – alonso s Dec 19 '17 at 18:42
  • Add -n to the autossh call and see if it makes a difference. And while you're at it drop the & from the very end of the same line. – B Layer Dec 19 '17 at 21:20
  • No difference. I also made an edit to the question. – alonso s Dec 20 '17 at 23:26
1

I assume you were following the directions from this website: https://raymii.org/s/tutorials/Autossh_persistent_tunnels.html

As you correctly observed, trying to execute

sudo autossh -M 10984 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /home/user/.ssh/id_rsa.pub -R 9999:localhost:22 user@machine-B

causes the additional prompts which automatically fail on start up.

One simple solution is to copy your SSH key from 'user' to root.

cp /home/user/.ssh/id_rsa.pub /root/.ssh/id_rsa.pub
cp /home/user/.ssh/id_rsa /root/.ssh/id_rsa -R

This works OK for me. The copy was performed from 'root' account so the ownership was automatically set to 'root'. Then run the autossh command from terminal (not boot) so the host becomes known to root. Modify your boot command to include the new path to key in root folder and you're set.

  • Copied the the keys to root. Command works when executed from the command line, but not when starting up. I still get errors $ssh exited with error status 255; restarting ssh$ when I runs on boot, but now the process belongs to the root account. – alonso s Feb 17 '18 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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