Shadowsocks 安装指南

前言

Shadowsocks(中文名称:影梭)是一个安全的socks5代理,用于保护网络流量,是一个开源项目,具有快速、安全、跨平台等特征。Shadowsocks 通过客户端以指定的密码、加密方式和端口连接服务器,成功连接到服务器后,客户端在用户的电脑上构建一个本地socks5代理。使用时将流量分到本地socks5代理,客户端将自动加密并转发流量到服务器,服务器以同样的加密方式将流量回传给客户端,以此实现代理上网。

what-is-shadowsocks

准备

操作系统:Debian 6
运行环境:Python

安装

1
2
apt-get install python-pip
pip install shadowsocks

启动

1
ssserver -p 443 -k password -m rc4-md5

不输出日志后台运行:

1
nohup ssserver -p 443 -k password -m rc4-md5 >/dev/null 2>&1 &

后台运行:

1
ssserver -p 443 -k password -m rc4-md5 --user nobody -d start

停止:

1
ssserver -d stop

开机运行:
/root/.profile 中加入

1
nohup ssserver -p 443 -k password -m rc4-md5 >/dev/null 2>&1 &

多用户配置文件 /etc/shadowsocks/server.json

1
2
3
4
5
6
7
8
9
10
11
12
{
"server": "server_ip",
"local_address": "127.0.0.1",
"local_port": 1080,
"port_password": {
"8388": "password",
"8389": "password"
},
"timeout": 30,
"method": "rc4-md5",
"fast_open": false
}

检查日志:

1
less /var/log/shadowsocks.log

另一种开机启动方式(推荐):
创建 /etc/init.d/shadowsocks,并添加:

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh
### BEGIN INIT INFO
# Provides: shadowsocks
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Fast tunnel proxy that helps you bypass firewalls
# Description: A secure socks5 proxy, designed to protect your Internet traffic.
### END INIT INFO

# Author: Teddysun <[email protected]>

name=shadowsocks
BIN=/usr/local/bin/ssserver
conf=/etc/shadowsocks/server.json
#pid=/var/run/shadowsocks.pid

start(){
$BIN -c $conf -d start
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
echo "$name start success"
else
echo "$name start failed"
fi
}

stop(){
pid=`ps -ef | grep -v grep | grep -v ps | grep -i "/usr/bin/python ${BIN}" | awk '{print $2}'`
if [ ! -z $pid ]; then
$BIN -c $conf -d stop
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
echo "$name stop success"
else
echo "$name stop failed"
fi
else
echo "$name is not running"
RETVAL=1
fi
}

status(){
pid=`ps -ef | grep -v grep | grep -v ps | grep -i "/usr/bin/python ${BIN}" | awk '{print $2}'`
if [ -z $pid ]; then
echo "$name is not running"
RETVAL=1
else
echo "$name is running with PID $pid"
RETVAL=0
fi
}

case "$1" in
'start')
start
;;
'stop')
stop
;;
'status')
status
;;
'restart')
stop
start
RETVAL=$?
;;
*)
echo "Usage: $0 { start | stop | restart | status }"
RETVAL=1
;;
esac
exit $RETVAL

授予执行权限

1
chmod a+x /etc/init.d/shadowsocks

接下来,添加开机启动

1
update-rc.d shadowsocks default

Debian 8:

1
systemctl enable shadowsocks

参考资料:

(完)