Skip to content

Instantly share code, notes, and snippets.

@polprog
Created October 8, 2017 14:47
Show Gist options
  • Save polprog/fa9fa2165a99b791ff4a0f3df9788933 to your computer and use it in GitHub Desktop.
Save polprog/fa9fa2165a99b791ff4a0f3df9788933 to your computer and use it in GitHub Desktop.
A small SSH tunnel helper script
#!/bin/bash
##################################
# Small SSH tunnel helper script
# polprog 2017
# http://polprog.net
##################################
SOCKET="vnctun"
USER="$2"
REMOTE="$3"
PORTCONF="$4"
if [ $# -lt 3 ]
then
echo "Usage: $0 start <remote user> <remote addr> <portconfig>"
echo "Or: $0 <stop|check> <remote user> <remote addr>"
echo "Where portconfig is <local port>:<local ip>:<remote port>"
echo "For example to tunnel remote's port 80 to local port 8080"
echo "Use 8080:127.0.0.1:80"
exit 1
fi
case "$1" in
start)
if [ $# -lt 4 ]
then
echo "Missing portconfig! see usage!"
exit 2
fi
ssh -M -S $SOCKET -L $PORTCONF -f -N -l $USER $REMOTE
;;
stop|check)
ssh -S $SOCKET -O $1 $USER $REMOTE
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment