Across the Great Wall we can reach every corner in the world.

1. 下载 ShadowsocksR

~> wget https://github.com/cndaqiang/shadowsocksr/archive/manyuser.zip
~> unzip manyuser.zip
~> cd shadowsocksr-manyuser
~/shadowsocksr-manyuser> ls

apiconfig.py  configloader.py  Dockerfile       initmudbjson.sh  mudb.json      README.rst      setup_cymysql.sh  switchrule.py
asyncmgr.py   CONTRIBUTING.md  importloader.py  LICENSE          mujson_mgr.py  run.sh          setup.py          tail.sh
CHANGES       db_transfer.py   initcfg.bat      logrun.sh        mysql.json     server_pool.py  shadowsocks       tests
config.json   debian           initcfg.sh       MANIFEST.in      README.md      server.py       stop.sh           utils

2. 修改 SSR 配置文件 config.json

SSR 配置文件路径为shadowsocks-manyuser/config.json

{
    "server": "xxx.xxx.xxx.xxx", // 服务器 IP
    "server_ipv6": "::",
    "server_port": 8388, // 服务器端口
    "local_address": "127.0.0.1",
    "local_port": 1080, // 本地端口

    "password": "password", // 密码
    "method": "aes-256-cfb", // 加密方式
    "protocol": "auth_aes128_md5", // 协议
    "protocol_param": "",
    "obfs": "origin", // 混淆
    "obfs_param": "",
    "speed_limit_per_con": 0,
    "speed_limit_per_user": 0,

    "additional_ports" : {}, // only works under multi-user mode
    "additional_ports_only" : false, // only works under multi-user mode
    "timeout": 120,
    "udp_timeout": 60,
    "dns_ipv6": false,
    "connect_verbose_info": 0,
    "redirect": "",
    "fast_open": false
}

3. 启动/停止 SSR

sudo python ./shadowsocks/local.py -c config.json -d start|stop

4. 安装 proxychains-ng

~> git clone https://github.com/rofl0r/proxychains-ng.git
~> cd proxychains-ng/
~/proxychains-ng> ./configure --prefix=/usr --sysconfdir=/etc
~/proxychains-ng> make && make install
~/proxychains-ng> make install-config

5. 修改 proxychains 配置文件

proxychains-ng 配置文件路径为/etc/proxychains.conf根据实际情况添加代理socks5 127.0.0.1 1080

## you'll need to enable it if you want to use an application that 
## connects to localhost.
# localnet 127.0.0.0/255.0.0.0

## RFC1918 Private Address Ranges
# localnet 10.0.0.0/255.0.0.0
# localnet 172.16.0.0/255.240.0.0
# localnet 192.168.0.0/255.255.0.0

# ProxyList format
#       type  ip  port [user pass]
#       (values separated by 'tab' or 'blank')
#
#       only numeric ipv4 addresses are valid
#
#
#        Examples:
#
#               socks5  192.168.67.78   1080    lamer   secret
#               http    192.168.89.3    8080    justu   hidden
#               socks4  192.168.1.49    1080
#               http    192.168.39.93   8080    
#               
#
#       proxy types: http, socks4, socks5
#        ( auth types supported: "basic"-http  "user/pass"-socks )
#
[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
socks5  127.0.0.1 1080

6. 设置 proxychains 别名

修改~/.bashrc,并设置 alias 别名


# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias pc='proxychains4'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

输入source ~/.bashrc重启终端后生效。

要想在终端命令中使用代理,只需在命令前加上pc。例如:pc yum install kubectl

7. 验证代理是否可用

~> pc

Usage:    proxychains4 -q -f config_file program_name [arguments]
    -q makes proxychains quiet - this overrides the config setting
    -f allows one to manually specify a configfile to use
    for example : proxychains telnet somehost.com
More help in README file

~> pc telnet www.google.com 443

[proxychains] config file found: /etc/proxychains.conf
[proxychains] preloading /usr/lib/libproxychains4.so
[proxychains] DLL init: proxychains-ng 4.13-git-10-g1198857
Trying 224.0.0.1...
[proxychains] Strict chain  ...  127.0.0.1:1080  ...  www.google.com:443  ...  OK
Connected to www.google.com.
Escape character is '^]'.

~> pc curl myip.ipip.net

[proxychains] config file found: /etc/proxychains.conf
[proxychains] preloading /usr/lib/libproxychains4.so
[proxychains] DLL init: proxychains-ng 4.13-git-10-g1198857
[proxychains] Strict chain  ...  127.0.0.1:1080  ...  myip.ipip.net:80  ...  OK
当前 IP:103.122.23.116  来自于:美国 加利福尼亚州 费利蒙  sakura-host.net

参考文章

  1. Ubuntu 16.04 安装 Python 版 SSR | cndaqiang
  2. Centos 7 作为 Client 连接 SSR | 简书
  3. cndaqiang/shadowsocksr | Github
  4. shadowsocksr-backup/shadowsocksr | Github
  5. ShadowsocksR 一键安装脚本 | Shadowsocks 非官方网站
  6. Linux CentOS 7 安装 SSR 过程 以及一些问题的处理 | 逆流水Team
  7. 通过 ProxyChains-NG 实现终端下任意应用代理 | CSDN