Last active
September 18, 2021 15:29
-
-
Save fionn/a1257c4ab6ef1c48d144ff9946c4082d to your computer and use it in GitHub Desktop.
Cheap SOCKS proxy using an SSH tunnel.
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 | |
# Launch SSH tunnel for SOCKS proxy. | |
set -euo pipefail | |
host="$1" | |
local_port=1080 | |
control_dir="$(dirname "$(mktemp -u)")" | |
control_path="$control_dir/ssh-control-%r@%h:%p" | |
trap 'echo "Failed to connect to host or control"' ERR | |
ssh -D $local_port -S "$control_path" -fNM "$host" | |
echo "Opened tunnel to $host. Use SOCKS v5 proxy, host 127.0.0.1:$local_port." | |
ssh -S "$control_path" -O check "$host" | |
control_path_expanded=$(ssh -S "$control_path" -G "$host" | grep "^controlpath " | sed "s/.* //g") | |
echo "Exit with \"ssh -S $control_path_expanded -O exit $host\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment