Skip to content

Instantly share code, notes, and snippets.

@Unbinilium
Last active November 3, 2019 06:51
Show Gist options
  • Save Unbinilium/afa0f9da7e00d5cc56651ccbc86acd99 to your computer and use it in GitHub Desktop.
Save Unbinilium/afa0f9da7e00d5cc56651ccbc86acd99 to your computer and use it in GitHub Desktop.
Command lines proxy

Usually we got a system based proxy but it not works in command line tools like the terminal. We could easily add such proxy by replacing the proxy information below and run them in terminal.

export http_proxy=protocol://username:password@proxyhost:port/
export ftp_proxy=protocol://username:password@proxyhost:port/
export telnet_proxy=protocol://username:password@proxyhost:port/

The protocol should be http, https or socks5 depends on what type of proxy you are using. Further more, we could add this to ~/.*shrc to initialize proxy when terminal start by sudo nano ~/.*shrc.

Let apt work with socks5 proxy, add -o Acquire::http::proxy="protocolh://proxyhost:proxyport/" as arguments, for example:

sudo apt-get -o Acquire::http::proxy="socks5h://127.0.0.1:1080/" update

Another big problem is using a proxy like socks5 in pip, git or even brew, let's have a try. For example, when setting up a socks5 proxy in pip, pysocks is required as a dependency and we add it by:

pip install pysocks

Then we cloud use pip with a socks5 proxy by: pip install <yourpacakge> --proxy socks5:proxyhost:port. Similarly we replace protocol with the proxy type you have to configure git. After that we use git with proxy just by git clone <yourgit>.

git config --global http.proxy protocol://username:password@proxyhost:port

To show the current configuration of all http sections. If you are in local then you drop the --global to see the current config.

git config --global --get-regexp http.*

If you're a macOS user with homebrew, you can try ALL_PROXY=protocol://username:password@proxyhost:port brew install <yourpackage>.

Finally you cloud easily disable these proxies. For shell in terminal you should remove the proxy settings in ~/.*shrc first and restart your terminal, or use unset <name_proxy>. For git you're supposed to clean the configuration by git config --global --unset http.proxy. We simplily add this as alieas like this(requird to replace with your proxy information):

alias proxy_enable="http_proxy=socks5://127.0.0.1:1080"
alias proxy_disable="unset http_proxy"
alias system_update="sudo apt-get -o Acquire::http::proxy="socks5h://127.0.0.1:1080/" update"
alias system_upgrade="sudo apt-get -o Acquire::http::proxy="socks5h://127.0.0.1:1080/" dist-upgrade"

Then just open new BASH window and type system_update, it actually execute sudo apt-get -o Acquire::http::proxy="socks5h://127.0.0.1:1080/" update and pass all apt traffic through socks5 proxy 127.0.0.1:1080.

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