1

I have set up the following upstart script:

# autossh

description     "autossh connections"

start on started dbus
stop on (runlevel [06] or stopped dbus)

respawn
respawn limit 5 60 # respawn max 5 times in 60 seconds

script
    export AUTOSSH_PIDFILE=/var/run/autossh.pid
    export AUTOSSH_POLL=60
    export AUTOSSH_FIRST_POLL=30
    export AUTOSSH_GATETIME=0
    export AUTOSSH_DEBUG=1
    exec sudo -H -u pi -s autossh -M 0 -R remoteport:127.0.0.1:localport remoteuser@remote.host
    exec sudo -H -u pi -s autossh -M 0 -R remoteport2:127.0.0.1:localport2 remoteuser@remote.host
end script

but every time after the start I get this error message:

ssh exited prematurely with status 0

How can I fix it?

Thanks

Peleke
  • 131
  • 1
  • 4
  • @Falcon Momot Or how about this remove the part about "raspbmc" and it's completely relevant and just helped me out immensely doing real live server administration. This should NOT be closed or downvoted. – John Culviner Dec 28 '15 at 18:27

2 Answers2

4

You need a -N option so that is doesn't create an interactive shell.

exec sudo -H -u pi -s autossh -M 0 -N -R remoteport:127.0.0.1:localport remoteuser@remote.host

From the man

 -N      Do not execute a remote command.  This is useful for just forwarding ports
mR_fr0g
  • 156
  • 4
0

Usually status 0 means that it was successful, but in your case I think that it means that it was successful in connecting but closed when it couldn't bind to the specified ports.

If remoteport[2] is a privileged port 1-1024, you wouldn't be able to bind to it unless you are root. You could change it and still leave localport to be the same.

If there is something already listening on the port you wouldn't be able to bind to it either.

The first thing you should do if my answers above were not 100% accurate, is to connect manually with ssh (removing the -M, adding -v):

ssh -v -Rremoteport:127.0.0.1:localport remoteuser@remote.host

Also, you should combine both -R statements into 1 ssh command, you don't want to run it as two if they are both connecting to the same server, like this:

ssh -v -Rremoteport:127.0.0.1:localport -Rremoteport2:127.0.0.1:localport2 remoteuser@remote.host

See what errors you get running the regular ssh command, but it's probably the port you chose.

MattPark
  • 303
  • 5
  • 20
  • `sudo -H -u pi -s autossh -M 0 -R remoteport:127.0.0.1:localport -p sshport -i /home/pi/.ssh/id_dsa remoteuser@remote.host` works but the upstart script exits immediately with the above error message. Do I have to add some switches like -f ? – Peleke Jul 02 '13 at 13:16