#!/bin/sh # This you can add to crontab: # @reboot /path/to/ssh_tun.sh >> /tmp/ssh_tun.tmp # * * * * * /opt/start_ssh_tunnel.sh >> /tmp/ssh_tun.tmp # Configure: KEY_PATH=/absolute/path/to/key USER=tun-user ADDR=my.domain.org LISTEN_PORT=12345 # Don't change below: GATEWAY="$LISTEN_PORT:127.0.0.1:22" OPT='-o PubkeyAuthentication=yes -o IdentitiesOnly=yes' FLAGS='-f -T -N -R' SSH_TUN_CMD="ssh $OPT $FLAGS $GATEWAY $USER@$ADDR -i $KEY_PATH" pgrep -f "$SSH_TUN_CMD" if [ $? -eq 0 ]; then exit 0 fi ping -c 3 $ADDR if [ $? -ne 0 ]; then exit 1 fi exec $SSH_TUN_CMD