Skip to content

Instantly share code, notes, and snippets.

@Karunamon
Created December 30, 2013 15:19
Show Gist options
  • Save Karunamon/8183305 to your computer and use it in GitHub Desktop.
Save Karunamon/8183305 to your computer and use it in GitHub Desktop.
SSH tunnel setup script. Source in your profile for awesomeness.
#!/bin/bash
function proxtun(){
#Validity check of settings
if [ ! -e ~/.proxtun ]; then
echo "No proxy user/host set. Please set up a remote machine with SSH"
echo "tunneling capability (with keys) and then put that user@host in"
echo "~/.proxtun"
return 5
fi
tunhost=`cat ~/.proxtun`
tunpid=`pgrep -f '\-D 9001 '`
if [ -z $tunpid ]; then
echo "Establishing SSH tunnel"
ssh -D 9001 -Nf -o ExitOnForwardFailure=yes $tunhost
tunpid=`pgrep -f '\-D 9001 '`
if [ -z $tunpid ]; then
echo "Error: Unable to set up tunnel."
fi
else
echo "Shutting down SSH tunnel"
kill -TERM $tunpid
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment