Setting Shadowsocks Server

The Initial Setting

1. Login VPS

2. Install shadowsocks

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

3. Edit configuration file

1
sudo vi /etc/shadowsocks.json
1
2
3
4
5
6
7
8
9
10
11
{
"server":"0.0.0.0",
"server_port":2016,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"<password>",
"timeout":300,
"method":"aes-256-cfb",
"fast_open":true,
"workers":1
}

4. Start shadowsocks

Start shadowsocks service as below:

1
ssserver -c /etc/shadowsocks.json

Start and stop shadowsocks service in background:

1
2
sudo ssserver -c /etc/shadowsocks.json -d start
sudo ssserver -c /etc/shadowsocks.json -d stop

shadowsocks logs will be saved in /var/log/shadowsocks.log

5. Special setting

For Azure VM, we need to add an Inbound rule in Network Security Group. The port should be the same as the one defined in /etc/shadowsocks.json file

Starting shadowsocks service Automatically on Boot

1. Create /etc/init.d/shadowsocks script

1
sudo vi /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
#!/bin/sh
### BEGIN INIT INFO
# Provides: shadowsocks
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO

start(){
ssserver -c /etc/shadowsocks.json -d start
}

stop(){
ssserver -c /etc/shadowsocks.json -d stop
}

case "$1" in
start)
start
;;
stop)
stop
;;
reload)
stop
start
;;
*)
echo "Usage: $0 {start|reload|stop}"
exit 1
;;
esac

2. Add execute permission for this script

1
sudo chmod +x /etc/init.d/shadowsocks
1
sudo update-rc.d shadowsocks defaults

Control service in Shell:

1
sudo service shadowsocks {start|reload|stop}

4. Edit /etc/rc.local file

Add the command in the /etc/rc.local script that is executed at the end of startup

1
sudo vi /etc/rc.local

Add the following command before exit 0

1
sudo service shadowsocks start