Skip to content

Instantly share code, notes, and snippets.

@heywoodlh
Last active August 22, 2017 20:51
Show Gist options
  • Save heywoodlh/b42b4641bf9ff926bba80b61bd8f930b to your computer and use it in GitHub Desktop.
Save heywoodlh/b42b4641bf9ff926bba80b61bd8f930b to your computer and use it in GitHub Desktop.
Simple port forwarding script via SSH
#!/usr/bin/env bash
PORT='80'
SSH_PORT='22'
USERNAME='root'
HOSTNAME='myserver.com'
if ssh -p "$SSH_PORT" -t -t -L 9000:127.0.0.1:"$PORT" "$USERNAME"@"$HOSTNAME" &
then
SSH_PID=$(echo $!)
sleep 5
open http://127.0.0.1:9000/
function pause(){
read -p "$*"
}
pause 'Press [Enter] key to exit...'
kill $SSH_PID
else
echo "ssh connection failed"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment