Created
October 8, 2017 14:47
-
-
Save polprog/fa9fa2165a99b791ff4a0f3df9788933 to your computer and use it in GitHub Desktop.
A small SSH tunnel helper script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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