Last active
March 28, 2023 05:18
-
-
Save amanaplan/4704517 to your computer and use it in GitHub Desktop.
Archived: Gateway script to tunnel to a service by creating and using a local SOCKS proxy via an SSH tunnel on your remote endpoint. Secure and faster than VPN.
This file contains 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 | |
CMD_DEFAULT=start | |
RUNNING=$(sudo networksetup -getsocksfirewallproxy Wi-Fi | grep 1080) | |
CMD=${1:-$CMD_DEFAULT} # Set default | |
if [ "$CMD" = "start" -a "$RUNNING" != "Port: 1080" ] | |
then | |
sudo ssh -C -D 1080 myusername@remote.example.com -f -N > /dev/null 2>&1 | |
sudo networksetup -setsocksfirewallproxy Wi-Fi localhost 1080 | |
sudo networksetup -setsocksfirewallproxystate Wi-Fi on | |
echo 'Gateway started.' | |
elif [ "$CMD" = "stop" -o "$running" = "Port: 1080" ] | |
then | |
sudo killall -u root -9 ssh | |
sudo networksetup -setsocksfirewallproxy Wi-Fi "" "" | |
sudo networksetup -setsocksfirewallproxystate Wi-Fi off | |
echo 'Gateway stopped.' | |
else | |
echo 'Error.' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment