通过ssh使用socket5代理访问github

作者 Lu Liang 日期 2018-09-29
通过ssh使用socket5代理访问github

假设github.com在墙外, 你现在可以通过以下配置方法去访问它。前提是你有一台墙外的机器。至于如何得到一台墙外的机器,这个方法很多,例如可以通过申请云虚拟机器等等,详细步骤就不在这里提了。通过这台机器做代理,你就可以爬墙,自由的放飞自我了。

Open ssh tunnel

The machine “proxyMachine” can visit github.com. We can open one tunnel between your laptop and proxyMachine by the following command.

ssh -TfnN -D 7070 proxyMachine

Config ssh proxy for github

Modify ~/.ssh/config to add proxy for github.com.

Host github.com
HostName github.com
User luliang
ProxyCommand nc -v -x 127.0.0.1:7070 %h %p
UseKeychain yes

Config http proxy for github

If you want to use http proxy. You also need to config git with ‘git config’

git config --global http.proxy 'socks5://127.0.0.1:7070'
git config --global https.proxy 'socks5://127.0.0.1:7070'

Config socket5 proxy for your browser.

There are two ways to config proxy for browser. You can choose one freely.

  • Setup proxy in system.

  • Setup proxy in chrome with plugin “SwitchyOmega”

Config socket5 proxy for your terminal such as iterm2.

在 .bashrc 或 .zshrc 中设置如下内容

alias setproxy="export http_proxy=socks5://127.0.0.1:7070; export https_proxy=$http_proxy"
alias unsetproxy="unset http_proxy; unset https_proxy"

或者手动设置终端代理:

export http_proxy="socks5://127.0.0.1:7070"
export https_proxy="socks5://127.0.0.1:7070"