Skip to content

Instantly share code, notes, and snippets.

@gotbadger
Created February 18, 2013 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gotbadger/4979243 to your computer and use it in GitHub Desktop.
Save gotbadger/4979243 to your computer and use it in GitHub Desktop.
Setup SSH tunnel on OSX
#!/bin/bash
# setup local
BIND_ADAPTER="en0"
LOCAL_PORT=4000
# setup remote
REMOTE_USER="user"
REMOTE_HOST="server.example.com"
REMOTE_PORT=9999
echo "Make sure $REMOTE_PORT is open on $REMOTE_HOST and 'GatewayPorts yes' is set in sshd.conf"
LOCAL=$(ifconfig $BIND_ADAPTER | grep 'inet ' | cut -d " " -f2 | awk '{print $1}')
echo "$REMOTE_HOST:$REMOTE_PORT -> $LOCAL:$LOCAL_PORT"
ssh $REMOTE_USER@$REMOTE_HOST -N -R $REMOTE_PORT:$LOCAL:$LOCAL_PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment