Skip to content

Instantly share code, notes, and snippets.

@nilusr
Forked from fearblackcat/proxy_for_terminal.md
Created September 29, 2020 09:31
Show Gist options
  • Save nilusr/3b88f39fd9c4e4fdc801a270eabb80a4 to your computer and use it in GitHub Desktop.
Save nilusr/3b88f39fd9c4e4fdc801a270eabb80a4 to your computer and use it in GitHub Desktop.

Revisions

  1. @fearblackcat fearblackcat renamed this gist Oct 4, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @fearblackcat fearblackcat created this gist Oct 4, 2017.
    104 changes: 104 additions & 0 deletions md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,104 @@
    # Shadowsocks Proxy

    ## [Server-side setup](https://github.com/shadowsocks/shadowsocks)

    ```sh
    apt-get install python-pip
    pip install shadowsocks

    sudo ssserver -p 443 -k password -m aes-256-cfb --user nobody -d start
    ```


    ## Client-side setup

    * Install Shadowsocks Client, e.g. run `brew cask install shadowsocksx` in Mac OSX.
    * SwitchSharp

    > Only config `SOCKS Host` to `127.0.0.1:1080` and select `SOCKS v5`


    # SOCKS 5 Through SSH Tunnel

    ```sh
    # `-N`: do not execute commands
    # `-D`: bind 1080 port and forward 1080 port to 22 port
    # `-i`: use pre-shared key `hello.pem`
    # `-p`: specify port used to connect to remote server
    ssh -ND 1080 -i ~/.ssh/hello.pem <username>@<your-remote-server-ip> -p 22
    ```


    ## Reference

    * [how-do-i-set-up-a-linux-proxy-for-my-mac by askubuntu](http://askubuntu.com/questions/143303/how-do-i-set-up-a-linux-proxy-for-my-mac)


    # Socks 5 in Terminal

    ## Using Proxychains-ng to socksify your command

    * Install `proxychains-ng` by running `brew install proxychains-ng`.
    * Config `/usr/local/Cellar/proxychains-ng/4.7/etc/proxychains.conf`, modify the following parameters.

    ```config
    [ProxyList]
    socks5 127.0.0.1 1080
    ```

    * Add `proxychains4` to the front of every command, e.g. `proxychains4 curl ipecho.net/plain`

    > Also works for Application like `Google Chrome` while `Safari` does not work, try `proxychains4 /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome `.
    > But this might slow down Chrome.

    > You can also use [dsocks](http://monkey.org/~dugsong/dsocks/) for mac(which does not work for me), [tsocks](http://tsocks.sourceforge.net/) for linux.

    ## Using Unix Proxy Environment Variable

    Add this script to `~/.bash_profile`.

    ```sh
    export http_proxy=socks5://127.0.0.1:1080
    export https_proxy=socks5://127.0.0.1:1080
    ```


    ## Config `curl` to use SOCKS5(Also works for `homebrew`)

    Add the following line to `~/.curlrc`. Since `homebrew` use `curl` to download the package, this will also enable `homebrew` to use SOCKS5.

    ```config
    socks5 = "socks5://127.0.0.1:1080"
    ```

    > There are no environment variables for SOCKS5 proxy servers in unix, so in order to use SOCKS5 in other utilities, check the man pages for existing tools to see if they have a configuration option for a SOCKS5 proxy and whether they have a configuration file that the configuration can be added to.


    ## Config `git` to use SOCKS5

    * For `https://` and `http://`(e.g. `http://github.com`, `https://github.com`), run the following script.

    ```sh
    git config --global http.proxy 'socks5://127.0.0.1:1080'
    git config --global https.proxy 'socks5://127.0.0.1:1080'
    ```

    * For `git://`(e.g. `git://github.com`), run `git config --global core.gitproxy 'socks5://127.0.0.1:1080'`
    * For ssh(e.g. `[email protected]`,`ssh://[email protected]`), add `ProxyCommand nc -x localhost:1080 %h %p` to `~/.ssh/config` file.

    > `git config --global ` is stored in `~/.gitconfig` while local config settings is in `./.git/config`.
    > To remove a configuration, e.g. run `git config --global --unset core.gitproxy`.

    ## Reference

    * [how to set socks5 proxy in the terminal by askubuntu](http://askubuntu.com/questions/610333/how-to-set-socks5-proxy-in-the-terminal)
    * [OS X Terminal Ignoring SOCKS Proxy Setup](http://superuser.com/questions/377199/os-x-terminal-ignoring-socks-proxy-setup)
    * [Git proxy through SOCKS 5 by cms-sw](http://cms-sw.github.io/tutorial-proxy.html)
    * [git proxy on segmentfault](http://segmentfault.com/q/1010000000118837)


    # Tools

    ```sh
    curl --socks5-hostname 127.0.0.1:1080 http://wtfismyip.com/json
    ```