Created
February 8, 2014 15:24
-
-
Save r-gr/8885381 to your computer and use it in GitHub Desktop.
Simple SSH tunnel script for OS X.
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
#! /usr/local/bin/fish | |
set -l server_ip 0.0.0.0 # change this | |
set -l server_user root | |
set -l local_port 1234 | |
function _ssh_tunnel_help | |
echo "usage: sshtunnel <command>\n" | |
echo " open Opens ssh tunnel to server and enables SOCKS proxy" | |
echo " close Closes ssh tunnel and disables SOCKS proxy" | |
echo " help Displays this message\n" | |
end | |
function sshtunnel | |
if [ $argv[1] ] | |
switch $argv[1] | |
case 'open' | |
sudo -v | |
echo "enabling SOCKS proxy..." | |
# sudo networksetup -setsocksfirewallproxy Wi-Fi 127.0.0.1 $local_port | |
sudo networksetup -setsocksfirewallproxy Ethernet 127.0.0.1 $local_port | |
# sudo networksetup -setsocksfirewallproxystate Wi-Fi on | |
sudo networksetup -setsocksfirewallproxystate Ethernet on | |
echo "tunneling..." | |
ssh -f -D $local_port -C -N $server_user@$server_ip | |
echo "tunnel opened." | |
case 'close' | |
sudo -v | |
echo "killing ssh processes..." | |
pkill ssh | |
pkill ssh-agent | |
echo "disabling SOCKS proxy..." | |
# sudo networksetup -setsocksfirewallproxystate Wi-Fi off | |
sudo networksetup -setsocksfirewallproxystate Ethernet off | |
echo "tunnel closed." | |
case '*' | |
_ssh_tunnel_help | |
end | |
else | |
_ssh_tunnel_help | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment