Openbsd init script for ssh VPN tunnel
Posted
by
manthis
on Server Fault
See other posts from Server Fault
or by manthis
Published on 2012-08-22T01:12:30Z
Indexed on
2012/12/07
17:11 UTC
Read the original article
Hit count: 265
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:
#!/bin/sh
#
# 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: autossh.host,v 1.6 2004/01/24 05:53:09 harding Exp $
#
ID=root
HOST=example.com
#AUTOSSH_POLL=600
#AUTOSSH_PORT=20000
#AUTOSSH_GATETIME=30
#AUTOSSH_LOGFILE=$HOST.log
#AUTOSSH_DEBUG=yes
#AUTOSSH_PATH=/usr/local/bin/ssh
export AUTOSSH_POLL AUTOSSH_LOGFILE AUTOSSH_DEBUG AUTOSSH_PATH AUTOSSH_GATETIME AUTOSSH_PORT
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/autossh.sh ]; then
echo -n 'ssh tunnel'
/usr/local/sbin/autossh.sh
fi
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:
inet 10.254.254.2 255.255.255.252 10.254.254.1
!/usr/local/sbin/autossh.sh
Your input is highly appreciated.
© Server Fault or respective owner