2

I have an upstart job /etc/init/tunnel.conf:

description "SSH Tunnel"

start on (net-device-up IFACE=eth0)
stop on runlevel[016]

respawn

exec autossh -nNT -o ServerAliveInterval=15 -R 12345:localhost:22 myuser@myserver

When I look at the /var/log/upstart/tunnel.log:

Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).

but if I try from terminal

autossh -R 12345:localhost:22 myuser@myserver

It connects to myserver without asking me for password (I have copied the SSH keys)

When I run it using sudo:

sudo autossh -R 12345:localhost:22 myuser@myserver

It asks me for myserver password, so I guess this is the problem I have with the upstart job. Why SSH is asking me for password we I run it as a root?

Giacomo1968
  • 3,542
  • 27
  • 38
Leosar
  • 123
  • 1
  • 5

1 Answers1

10

When autossh invoked by sudo or init process, autossh use identity/ssh-keys file provided by root user (e.g. /root/.ssh/sshkeys). When you try run autossh from terminal, maybe you use non-root user. Thus, autossh use identity/ssh-keys file provided by that user (e.g /home/non-root/.ssh/sshkeys).

To get expected behavior, you can provided identity file in tunnel.conf. To do that, modify last line to

exec autossh -nNT -i /home/non-root/.ssh/sshkeys -o ServerAliveInterval=15 -R 12345:localhost:22 myuser@myserver

More info in Autossh with Ubuntu Upstart

masegaloeh
  • 18,236
  • 10
  • 57
  • 106
  • Thanks now it works, besides teere is a problem with the command you wrote, the -o is misplaced should be `exec autossh -nNT -i /home/non-root/.ssh/sshkeys -o ServerAliveInterval=15 -R 12345:localhost:22 myuser@myserver` – Leosar May 06 '14 at 19:54
  • Now I have the problem with the remote computer previously I connected but now I cant `$ ssh leo@localhost -p 54321 ssh_exchange_identification: Connection closed by remote host` – Leosar May 06 '14 at 20:03
  • masegaloeh, great answer! Why use `exec` btw? – Alexander Suraphel Mar 09 '16 at 08:05