I have set up the following upstart script:

# autossh

description     "autossh connections"

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

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

    export AUTOSSH_PIDFILE=/var/run/autossh.pid
    export AUTOSSH_POLL=60
    export AUTOSSH_FIRST_POLL=30
    export AUTOSSH_DEBUG=1
    exec sudo -H -u pi -s autossh -M 0 -R remoteport: remoteuser@remote.host
    exec sudo -H -u pi -s autossh -M 0 -R remoteport2: 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?


closed as off-topic by Falcon Momot, Ward, mdpc, Nathan C, Magellan Aug 7 '13 at 5:02

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must be relevant to professional system administration. Server Fault is a site dedicated to professionals; novice questions are off-topic. Please see the Help Center for more information on topicality. The best advice we can give you is to hire a professional to help you out." – Falcon Momot, Ward, mdpc, Nathan C
If this question can be reworded to fit the rules in the help center, please edit the question.

  • @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

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: remoteuser@remote.host

From the man

 -N      Do not execute a remote command.  This is useful for just forwarding ports

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: 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: -Rremoteport2: remoteuser@remote.host

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

  • sudo -H -u pi -s autossh -M 0 -R remoteport: -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 2 '13 at 13:16

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