Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have set up the following upstart script on my raspbmc:

# 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

share|improve this question

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.

2 Answers 2

up vote 1 down vote accepted

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
share|improve this answer
    
Thanks, that did the trick! –  Peleke Aug 9 '13 at 14:36

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.

share|improve this answer
    
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 2 '13 at 13:16

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