Step 1: Install Shadowsocks Client

Shadowsocks is an open-source proxy project to help people visit some websites :). To speed up web surfing, we need to install a Shadowsocks client first.

For Ubuntu:

sudo apt-get install shadowsocks

For Mac:

brew install shadowsocks-libev

You can also download a GUI client from https://sourceforge.net/projects/shadowsocksgui/

Create a directory named shadowsocks: mkdir shadowsocks, cd into it, create a file named shadowsocks.json with the following content:

1
2
3
4
5
6
7
8
{
"server": "139.162.10.88", // your server ip address
"server_port": 12345, // your server port
"local_port": 1080,
"password": "your_password",
"timeout": 600,
"method": "aes-256-cfb" // your encrption method
}

Run the following command to start the Shadowshocks client:

sudo nohup sslocal -c ./shadowsocks.json &

It’ll open a local port to wait for the connection, and here it’s 1080.

Step 2: Use Shadowsocks Client as HTTP Proxy

First, let’s do some check:

$ curl ip.gs
当前 IP:59.110.66.150 来自:中国北京北京 阿里云/电信/联通/移动/铁通/教育网

Yes, I’m safely protected by the wall :).

With the environment variable http_proxy set, we can travel abroad:

$ http_proxy=socks5://localhost:1080 curl ip.gs
当前 IP:139.162.10.88 来自:新加坡新加坡 linode.com

However, some command line tools (such as npm) don’t support socks5 protocol, and under the help of polipo we can convert socks5 into http.

For Ubuntu:

sudo apt-get install polipo

Edit the config file at /etc/polipo/config, and append the following two lines:

socksParentProxy = "localhost:1080"
socksProxyType = socks5

Finally, restart polipo:

sudo service polipo stop
sudo service polipo start

And for Mac:

brew install polipo

Edit file /usr/local/opt/polipo/homebrew.mxcl.polipo.plist, add the socksParentProxy:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>homebrew.mxcl.polipo</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/polipo/bin/polipo</string>
<string>socksParentProxy=localhost:1080</string>
</array>
<!-- Set `ulimit -n 65536`. The default macOS limit is 256, that's
not enough for Polipo (displays 'too many files open' errors).
It seems like you have no reason to lower this limit
(and unlikely will want to raise it). -->
<key>SoftResourceLimits</key>
<dict>
<key>NumberOfFiles</key>
<integer>65536</integer>
</dict>
</dict>
</plist>

Restart polipo:

1
2
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.polipo.plis

Also you can make it start when the system launches:

ln -sfv /usr/local/opt/polipo/*.plist ~/Library/LaunchAgents

Now you can the the http proxy offered by polipo:

$ http_proxy=http://localhost:8123 curl ip.gs
当前 IP:139.162.10.88 来自:新加坡新加坡 linode.com

You can set it globally by (here I just add https_proxy by the way):

export http_proxy=http://localhost:8123
export https_proxy=http://localhost:8123

And stop the proxy with unset http_proxy or (unset https_proxy).

Also, you can put the two export lines into your .zshrc(or, .bashrc) to set the proxies automatically when you start a new shell session.

source ~/.zshrc or restart a new session, you can see the proxy works:

$ curl ip.gs
当前 IP:139.162.10.98 来自:新加坡新加坡 linode.com

Step 3: Set Up git Proxy

First try it out:

In Aliyun, it’s quite slow. We can let git use the proxy with the following command:

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

It will create a http section in your ~/.gitconfig file:

[http]
proxy = socks5://127.0.0.1:1080

Now, you can clone any repository in Github much faster.

Step 4: Set Up pip Proxy

In Aliyun, the connection of pip is very slow:

$ pip install tornado
Collecting tornado
Downloading tornado-4.4.2.tar.gz (460kB)
4% |█▍ | 20kB 11kB/s eta 0:00:37

If you set the https_proxy environment variable, the following steps are saved. However, since proxychains is very handy, I’ll spend one section to detail it’s configuration.

For Ubuntu:

sudo apt-get install proxychains

Change the config file at ~/.proxychains/proxychains.conf, and change the [ProxyList] in it:

[ProxyList]
socks5 127.0.0.1 1080
# You can also use the http proxy polipo offers
# http 127.0.0.1 8123

For Mac, use proxychains-ng instead:

$ brew install proxychains-ng

Change the config file at /usr/local/etc/proxychains.conf, and change the [ProxyList] in it like what we did for Ubuntu.

Now you can install packages much faster.

For Ubuntu, put proxychains before pip:

$ proxychains pip install tornado
ProxyChains-3.1 (http://proxychains.sf.net)
Collecting tornado
|D-chain|-<>-127.0.0.1:1080-<><>-151.101.36.223:443-<><>-OK
Downloading tornado-4.4.2.tar.gz (460kB)
51% |████████████████▍ | 235kB 553kB/s eta 0:00:01

For Mac, use proxychains4 instead:

proxychains4 pip install Faker
[proxychains] config file found: /usr/local/Cellar/proxychains-ng/4.11/etc/proxychains.conf
[proxychains] preloading /usr/local/Cellar/proxychains-ng/4.11/lib/libproxychains4.dylib
[proxychains] DLL init: proxychains-ng 4.11
[proxychains] DLL init: proxychains-ng 4.11
Collecting Faker
[proxychains] Strict chain ... 127.0.0.1:1080 ... pypi.python.org:443 ... OK
Downloading Faker-0.7.7-py2.py3-none-any.whl (562kB)
100% |████████████████████████████████| 563kB 1.3MB/s
...
Installing collected packages: Faker
Successfully installed Faker-0.7.7

Step 5: Set npm Proxy

If you set the shell http_proxy and https_proxy, npm would take advantage of the proxy. But you can always make things safer by instruct the following commands:

npm config set proxy http://localhost:8123
npm config set https-proxy http://localhost:8123

Also with the help of proxychains, you can make npm traffic go through the proxy. But you should make sure not use proxychains with the http_proxy and https_proxy environmant variables set at the same time.

Conclusion

We can live a safe and slow life, or a “dangerous” but fast one, and Shadowsocks with all these proxy tools will help us to achieve that. Thanks all these “wanderlusters” who wallow in freedom to create these awesome stuff, and wish you a good journey with the “ladder”. Beyond the wall, there is the world.

命令行command line 使用 http proxy的设置方法 Setting Up HTTP Proxy in Terminal的更多相关文章

  1. 使用mysql 命令行,增加 ,删除 字段 并 设置默认值 及 非空

    使用mysql 命令行,增加 ,删除 字段 并 设置默认值 及 非空 添加 alter table table_name add field_name field_type; 添加,并设置默认值,及非 ...

  2. 命令行下从bak文件恢复sqlserver数据库方法

    命令行下从bak文件恢复sqlserver数据库方法 注:本文所示访问从SqlServer 2000 - 2014版都是通用的 参考:http://blog.sina.com.cn/s/blog_5c ...

  3. Windows命令行command的Shell命令详细解析和语法

    CMD命令大全及详细解释和语法 Microsoft Windows XP [版本 5.1.2600] 有关某个命令的详细信息,请键入 HELP 命令名 ASSOC    显示或修改文件扩展名关联. A ...

  4. mysql: "Warning: Using a password on the command line interface can be insecure." 解决方法

    错误重现: 命令行或者shell脚本中执行以下命令,如果您当前服务器mysql版本是大于5.6的,则会出现警告:Warning: Using a password on the command lin ...

  5. 命令行向php传入参数的两种方法

    ##$argv or $argc  $argv 包含当运行于命令行下时传递给当前脚本的参数的数组.  $argv[0]  就是脚本文件名. $argc 包含当运行于命令行下时传递给当前脚本的参数的数目 ...

  6. Linux命令行修改IP、网关、DNS的方法

    Linux中在命令行中修改IP地址.网关.DNS的方法. 网卡eth0    IP修改为 102.168.0.1 复制代码代码如下: ifconfig eth0 102.168.0.1 netmask ...

  7. windows命令行模式下无法打开python程序解决方法

    今天刚开始学Python,首先编写一个简单地hello world程序,想在命令行模式运行,结果出现下面: 经过一番思考,发现用cd命令可以解决这件事,看下图: 这样就解决了.

  8. linux通过命令行查看MySQL编码并修改-简洁版方法

    云服务器环境:CentOS 7.4 因为服务器配置较低,故使用MySQL5.5 未进行设置前 1.查看字符编码: mysql> show variables like '%character%' ...

  9. 利用命令行删除Android系统自带应用的方法

    声明:本博客为原创博客.未经同意,不得转载!小伙伴们假设是在别的地方看到的话,建议还是来csdn上看吧(链接为http://blog.csdn.net/bettarwang/article/detai ...

随机推荐

  1. emwin之点击窗口的无效部分来实现一些功能

    @2018-07-27 触摸屏幕窗口的无效部分实现 Dropdown 部件的折叠操作 > 具体代码 case WM_TOUCH: if (pMsg->Data.p) // Somethin ...

  2. luogu1850 [NOIp2016]换教室 (floyd+dp)

    首先floyd求出每两点间的距离(注意自己到自己的距离要设成0) 然后就是dp了 一开始照着Lifeguards的样子,钦定了一下i这个点一定要选,然后发现复杂度不对,还想了好长时间优化 然后一翻题解 ...

  3. SPI接口扫盲 SPI定义/SPI时序(CPHA CPOL)

    SPI接口扫盲   douqingl@gmail.com   为何要写这篇文档?百度上找出来的SPI接口中文描述都说的太过简略,没有一篇文档能够详尽的将SPI介绍清楚的.wikipedia英文版[注释 ...

  4. ioi2018集训队自选题:最短路练习题

    题意:链接 定义pos[i]表示i这个值在数组里的下标. 我们先用单调栈找到每个元素左边和右边第一个比它大的元素$l_i$和$r_i$,然后建一棵二叉树,我们就叫做maxtree吧 (upd:mdzz ...

  5. poj 2785(折半枚举+二分搜索)

    传送门:Problem 2785 题意: 给定 n 行数,每行都有 4 个数A,B,C,D. 要从每列中各抽取出一个数,问使四个数的和为0的所有方案数. 相同数字不同位置当作不同数字对待. 题解: 如 ...

  6. item2乱码问题

    使用的是 mac 环境,本地使用终端打开中文可以正常显示,但是连接远端服务器上发现就编程乱码了,之前一直是好好的,但是突然有一天开始就乱码了,怀疑是我电脑升级后导致系统环境配置发生变化引起的.直接上解 ...

  7. P4994 终于结束的起点

    P4994 终于结束的起点 现在,给你一个模数 M,请你求出最小的 n > 0,使得 \(\mathrm{fib}(n) \bmod M = 0, \mathrm{fib}(n + 1) \bm ...

  8. Telnet的三种登录方式

    Telnet的三种登录方式 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.华为创建telnet的三种验证方式 首先,我们可以简单的看一个拓扑图,让我们可以在亦庄的路由器上对双桥 ...

  9. 《超哥带你学Linux》

    前言 “Linux?听说是一个操作系统,好用吗?” “我也不知道呀,和windows有什么区别?我能在Linux上玩LOL吗” “别提了,我用过Linux,就是黑乎乎一个屏幕,鼠标也不能用,不停地的敲 ...

  10. HDU - 3521 An easy Problem(矩阵快速幂)

    http://acm.hdu.edu.cn/showproblem.php?pid=3521 题意 对于矩阵A,求e^A的值. 分析 这个定眼一看好像很熟悉,就是泰勒展开,可惜自己的高数已经还给老师了 ...