Simple shell function to enable/disable system-wide Tor SOCKS proxy on macOS.
- Configures macOS system-level SOCKS proxy to route traffic through Tor
- Manages Tor daemon lifecycle (start/stop)
- Sets shell environment variables for CLI tools
- Supports multiple network interfaces (Wi-Fi, USB Ethernet, etc.)
brew install torsudo mkdir -p /opt/homebrew/var/lib/tor
sudo chown "$(whoami)" /opt/homebrew/var/lib/torEdit Tor config:
vim /opt/homebrew/etc/tor/torrcAdd the following:
Log notice stderr
DataDirectory /opt/homebrew/var/lib/tor
SocksPort 127.0.0.1:9050
Open your shell config:
vim ~/.zshrc # or ~/.bashrc for bashAdd the torctl() function from torctl.sh at the end of the file.
Reload shell config:
source ~/.zshrc # or source ~/.bashrctorctl statustorctl onThis will:
- Start Tor daemon via brew services
- Wait for Tor to be ready (port 9050)
- Configure system SOCKS proxy for all network interfaces
- Set shell proxy environment variables (
ALL_PROXY,HTTP_PROXY,HTTPS_PROXY)
torctl offThis will:
- Disable system SOCKS proxy
- Unset shell proxy variables
- Stop Tor daemon
torctl statusShows:
- Tor service state (brew services)
- Port 9050 listener status
- System proxy configuration
- Per-interface SOCKS settings
- Shell proxy environment variables
Browser (system-wide):
torctl on
open https://check.torproject.org
# Should show "Congratulations. This browser is configured to use Tor."CLI (curl):
torctl on
curl -s https://check.torproject.org | grep -i "Congratulations"
# Should output: Congratulations. This browser is configured to use Tor.Check your IP:
torctl on
curl https://api.ipify.org
# Should show Tor exit node IP (not your real IP)
torctl off
curl https://api.ipify.org
# Should show your real IPIf your network interface name differs from default (Wi-Fi, RNDIS/Ethernet Gadget), edit the SERVICES array in the function:
# List all network services
networksetup -listallnetworkservices
# Edit function
vim ~/.zshrc
# Change:
local SERVICES=(
"Wi-Fi"
"Your Interface Name Here"
)# Stop and remove Tor
torctl off # or manually: brew services stop tor
brew uninstall tor
# Remove Tor data and configs
sudo rm -rf /opt/homebrew/etc/tor
sudo rm -rf /opt/homebrew/var/lib/tor
rm ~/Library/LaunchAgents/homebrew.mxcl.tor.plist 2>/dev/null || true
# Remove function from shell config
vim ~/.zshrc # delete torctl() function
source ~/.zshrc- This routes traffic through Tor but does not guarantee anonymity
- Browser fingerprinting, WebRTC leaks, and application-level identifiers can still expose you
- For serious anonymity needs, use Tor Browser
- System-wide proxy means all apps use Tor (can be slow)
- macOS (tested on Ventura/Sonoma)
- Homebrew
sudoaccess (fornetworksetupcommands)nc(netcat) - pre-installed on macOS
Apache License