Created
May 12, 2017 21:32
-
-
Save mmyers1474/ba94e0dddd3b78e68915ded318250398 to your computer and use it in GitHub Desktop.
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
ssh -D 8123 -f -C -q -N sammy@example.com | |
Explanation of arguments | |
-D: Tells SSH that we want a SOCKS tunnel on the specified port number (you can choose a number between 1025-65536) | |
-f: Forks the process to the background | |
-C: Compresses the data before sending it | |
-T Disable pseudo-tty allocation | |
-q: Uses quiet mode | |
-N: Tells SSH that no command will be sent once the tunnel is up | |
-n Redirects stdin from /dev/null (actually, prevents reading from stdin). | |
function ssh-proxy () { | |
sub_cmd="${1}" | |
proxy_addr="${2}" | |
case "${sub_cmd}" in | |
'start') | |
echo "Starting SSH for a SOCKS proxy tunnel." | |
ssh -D -1080 -f -C -T -q -N -n "${proxy_addr}" && sshproxy_pid="$!" | |
;; | |
'status') | |
if [[ -n "${sshproxy_pid}" ]] && [[ -n $(ps -ef | grep ${sshproxy_pid}) ]]; then | |
echo "The SSH SOCKS proxy is running." | |
else | |
echo "The SSH SOCKS proxy is NOT running." | |
fi | |
;; | |
'stop') | |
if [[ -z ${sshproxy_pid} ]] || [[ -z $(ps -ef | grep ${ssh-pid}) ]]; then | |
kill -1 -p ${sshproxy_pid}; read -t 5 | |
[[ -z ${sshproxy_pid} ]] && kill -2 -p ${sshproxy_pid}; read -t 5 | |
[[ -z ${sshproxy_pid} ]] && kill -3 -p ${sshproxy_pid}; read -t 5 | |
[[ -z ${sshproxy_pid} ]] && kill -9 -p ${sshproxy_pid}; read -t 5 | |
[[ -z ${sshproxy_pid} ]] && echo "Unable to kill SSH SOCKS proxy process." | |
fi | |
;; | |
esag | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment