ss-bash
Shadowsocks traffic management script
- Currently only supports the Python version of Shadowsocks
- Currently only supports IPv4 traffic statistics
System Requirements
- shadowsocks-python
- Linux (Debian 7 recommended; other systems untested)
How It Works
Different users are assigned different ports. iptables rules are used to obtain traffic for each port. The script runs in a loop and, at fixed time intervals, calculates traffic usage based on the iptables results. When traffic exceeds the limit, it adds the corresponding iptables
reject rule for that port to disable it.
Instructions
First Use
Download the Software
Chinese version:
git clone https://github.com/hellofwy/ss-bash
Or:
wget https://github.com/hellofwy/ss-bash/archive/v1.0-beta.3.tar.gz
English version (thanks to @Yaoshicn for the contribution):
git clone https://github.com/hellofwy/ss-bash
cd ss-bash
git checkout en
Or:
wget https://github.com/hellofwy/ss-bash/archive/v1.0-beta.3-en.tar.gz
Before the first run, create a new user first
For example, if the new user’s port is 8388, the password is passwd, and the traffic limit is 10GB, run:
sudo ss-bash/ssadmin.sh add 8388 passwd 10G
Start ssserver
sudo ss-bash/ssadmin.sh start
For other commands, please check the help by running:
sudo ss-bash/ssadmin.sh help
Or click the link: https://github.com/hellofwy/ss-bash/blob/master/sshelp
Customize the ssserver configuration
Open the ssmlt.template file and add the relevant options.
Please note that each option must be followed by a comma (‘,’).
The default options are:
"server": "0.0.0.0",
"timeout": 60,
"method": "aes-256-cfb",
For example, after adding the fastopen and worker options:
"server": "0.0.0.0",
"timeout": 60,
"method": "aes-256-cfb",
"fast_open": true,
"workers": 5,
After making changes, if ssserver is running, please execute the following command to reload the file and start:
sudo ss-bash/ssadmin.sh soft_restart
Modify the traffic statistics interval
The default traffic sampling interval is 5 minutes
The traffic interval can be adjusted according to actual needs, but it is best not to make it too small, for example, less than 10 seconds
Open the sslib.sh file and modify the value of INTERVEL, in seconds. For example, to set the traffic interval to 10 minutes:
INTERVEL=600
Modify the ssserver file location
If shadowsocks was not installed using apt-get or pip and the ssserver file cannot be found automatically, please manually specify the exact location of the program.
Open the sslib.sh file and modify the value of SSSERVER. For example, if the path to ssserver is /usr/local/bin/ssserver, change it to
SSSERVER=/usr/local/bin/ssserver
Related files in the folder
- ssadmin.sh – Management program; all commands are executed through this program
-
sscounter.sh –
Traffic statistics program. Automatically invoked and executed by ssadmin.sh. Note: do not run this program manually. -
sslib.sh –
Contains some parameter configurations and traffic statistics functions. Automatically invoked and executed by ssadmin.sh. Note: do not run this program manually. - ssmlt.template – Configuration file for ssserver
After the program runs, it will generate the following files:
-
ssmlt.json –
The configuration file actually used by ssserver, generated from the user list and ssmlt.template -
ssusers –
User list, including port, password, and traffic limit parameters. The ssadmin.sh showpw
command displays the contents of this file. -
sstraffic –
User traffic usage, including traffic limits, used traffic, remaining traffic, etc. The ssadmin.sh
show command displays the contents of this file. - traffic.log – User traffic records, for internal program use.
-
Other files –
.tmp, .lock, .pid and other files, the tmp folder and the files within it are for internal program use. Please do not delete them manually.