linuxbootssh-tunnelautosshrc.d

issue with restarting autossh reverse tunnel on boot


I seem to have a weird issue: I want to restart a reverse ssh tunnel on boot, I've tried it with an init script (that works fine when executed as user) and with an added line in /etc/rc.d but none of it works. What I get after boot is:

$ ps ax  | grep autossh
  397 pts/10   S+     0:00 grep --color=auto autossh
 1351 ?        Ss     0:00 /usr/lib/autossh/autossh -M 22221    -N -o PubkeyAuthentication=yes -o PasswordAuthentication=no -i ~/.ssh/etherwan.key -R 19999:localhost:22 ubuntu@server

but I'm unable to login from server. So I did the following after boot:

$ sudo killall -KILL autossh
[sudo] password for ron: 
$ /usr/bin/autossh -M 22221 -f -N -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i ~/.ssh/etherwan.key -R 19999:localhost:22 ubuntu@server

upon which I can login using port 19999 just fine!

The keys permissions look like: (but root should not need to care, would it?)

$ ls -l ~/.ssh/etherwan.key
-r-------- 1 ron ron 1675 Nov  6 04:15 /home/ron/.ssh/etherwan.key

Solution

  • Replace ~/.ssh/etherwan.key in your rc.d script with /home/ron/.ssh/etherwan.key

    The '~' character is expanded to the user's home directory by the shell, but rc.d scripts are run as root.