Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a server hosting SSH tunnels and Openbsd 4.5 clients connecting to it.

Things work just fine but I am in the need of automating the connection from the client to the server. So that if the client is accidentally rebooted, then the connection initiates unattended.

So it should be as straight forward as to include the ssh connection in an init script. However I have miserably failed to do so by including it to /etc/rc.local, which is the file I usually do this sort of things in.

Right now I am using autossh to also restart the connection if necessary and the script that I put on /etc/rc.local follows:

# Example script to start up tunnel with autossh.
# This script will tunnel 2200 from the remote host
# to 22 on the local host. On remote host do:
#     ssh -p 2200 localhost
# $Id:,v 1.6 2004/01/24 05:53:09 harding Exp $



autossh -2 -f -M 20000 ${ID}@${HOST}

The script detaches just fine when run manually so I just include it on /etc/rc.local as

echo -n 'starting local daemons:'

if [ -x /usr/local/sbin/ ]; then
   echo -n 'ssh tunnel'

echo '.'

I have also tried calling it from /etc/hostname.tun0 in case there may be issues with /etc/rc.local not being called at the right time when network connections are ready, so I would use:


Your input is highly appreciated.

share|improve this question

I failed to complete understand your question: are you sure your autossh is run? If you don't find the tunnel open upon restart, it might be that it is not even started or that it has completed immediately because of an error. If order to check it, you may insert a call to "logger" command and log a message via syslog before and after running autossh, so you are sure that it is run. Please include the shell $rc variable in the second call to "logger" command.

Another option would be to run ssh (without autossh) from /etc/inittab as explained in this other question: runuser in rc.local

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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