Skip to content

Instantly share code, notes, and snippets.

@MuntashirAkon
Last active November 2, 2019 10:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save MuntashirAkon/fc6e7e85ada12fa1576dd0fe5ff8da8f to your computer and use it in GitHub Desktop.
Guide to enable macOS Terminal to respect system proxy

Copy and paste the code below at the beginning of ~/.bash_profile.

export http_proxy=`scutil --proxy | awk '\
  /HTTPEnable/ { enabled = $3; } \
  /HTTPProxy/ { server = $3; } \
  /HTTPPort/ { port = $3; } \
  END { if (enabled == "1") { print "http://" server ":" port; } }'`
export HTTP_PROXY="${http_proxy}"
export https_proxy=`scutil --proxy | awk '\
  /HTTPSEnable/ { enabled = $3; } \
  /HTTPSProxy/ { server = $3; } \
  /HTTPSPort/ { port = $3; } \
  END { if (enabled == "1") { print "http://" server ":" port; } }'`
export HTTPS_PROXY="${https_proxy}"

Source: https://dmorgan.info/posts/mac-network-proxy-terminal/

Note: If you're using Tor, SOCKS proxy isn't supported by Terminal, so add HTTPTunnelPort 9080 at /usr/local/etc/tor/torrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment