shadowsocks-hub
shadowsocks-hub copied to clipboard
A web app managing shadowsocks users, servers, nodes, products, accounts, and traffic. Suitable for internal use by companies, organizations, and friends.
Shadowsocks Hub (v0.3.0)
It is a web app for managing shadowsocks users, servers, nodes (a.k.a. exit points), products, accounts, and traffic. It is best suitable for companies, organizations, and groups of friends to manage their internal shadowsocks infrastructures.
Installation (Docker)
-
Install Docker.
-
Install Docker Compose.
-
Download Shadowsocks Hub:
cd ~ git clone https://github.com/shadowsocks/shadowsocks-hub.git -
Create an environment file
.env:cd ~/shadowsocks-hub touch .env -
Add the following configuration to
.env:CODE_SECRET=changeThisSecret MYSQL_PASSWORD=changeThisPasswordChange the value of
CODE_SECRETwith a long and random string.
Change the value ofMYSQL_PASSWORDwith another long and random string. -
Create a directory for digital certificate:
cd ~/shadowsocks-hub mkdir ssl -
Set up digital certificate
Shadowsocks Hub uses https for all web traffic. It requires you to set up a digital certificate. You may obtain your digital certificate and key pair from any Certificate Authority (e.g. Let's Encrypt). Then rename the certificate file to
server.certand the key file toserver.key. Finally, copy bothserver.certandserver.keyto~/shadowsocks-hub/ssldirectory. -
Create and start Docker container:
cd ~/shadowsocks-hub docker-compose up -dThe first time will take a while (a few seconds ~ few minutes), in order to download docker images from Docker Hub and run them. So be patient. ;-)
-
Shadowsocks Hub uses shadowsocks-restful-api to manage shadowsocks node. Install it on every server acting as a shadowsocks node.
Non-Docker Installation (deprecated)
This installation method has been deprecated and will be removed in the future. Please use the above mentioned docker installation method.
-
Install Nodejs 8 or above.
-
Install MySQL.
-
Download and install Shadowsocks Hub:
cd ~ git clone https://github.com/shadowsocks/shadowsocks-hub.git cd ~/shadowsocks-hub npm i sudo npm i -g knex sudo npm i -g pm2 -
Create a MySQL database
sshub:CREATE DATABASE sshub; -
Edit PM2 config file
~/shadowsocks-hub/ecosystem.config.js, change the following configurations to your local settings :JWT_SECRET: '2wk0M@ow094B^&9k3==~o2soejd$sEEo@2(', DATABASE_HOST: 'localhost', DATABASE_PORT: '3306', DATABASE_USER: 'root', DATABASE_PASSWORD: 'd4f889df22769f54', Change the value of `JWT_SECRET` with a long and random string. Change the values about the MySQL database connection to your local configurations. -
Initialize database:
cd ~/shadowsocks-hub knex migrate:latest --env production -
Set up digital certificate
Shadowsocks Hub uses https for all web traffic. It requires you to set up a digital certificate. You may obtain your digital certificate and key pair from any Certificate Authority (e.g. Let's Encrypt). Then rename the certificate file as
server.certand the key file asserver.key. Finally, copy bothserver.certandserver.keyto~/shadowsocks-hub. -
Give non-root user permission to use port 80, 443
Shadowsocks Hub requires listenning to port 80 and 443. The following commands allow a non-root user to use both ports. This is the best practice from security point of view.
sudo apt-get install libcap2-bin sudo setcap cap_net_bind_service=+ep /usr/bin/node -
Shadowsocks Hub uses shadowsocks-restful-api to manage shadowsocks node. Install it on every server acting as a shadowsocks node.
Update from non-Docker installation to Docker installation
-
Make above mentioned docker version installation.
-
Backup existing database:
cd ~/shadowsocks-hub mysqldump -u root -p sshub > backup.sql -
Restore the backup to docker MySQL container:
cd ~/shadowsocks-hub docker-compose up -d cat backup.sql | docker exec -i shadowsocks-hub_db_1 mysql -u root --password=MYSQL_PASSWORD sshubNote replace
MYSQL_PASSWORDwith your configration in.envfile.
Run
-
Run Shadowsocks Hub:
cd ~/shadowsocks-hub docker-compose up -d -
Visiting Shadowsocks Hub:
Visiting your Shadowsocks Hub website using your server domain name in a web browser.
-
Change admin credential
For the sake of security, you should immeidately change the default admin user username and password upon installation. This can be done by
loginas the admin user and thenupdatethe username and password. The default username and password for the admin user are[email protected]andpleaseChangePassword, respectively.
-
Run shadowsocks-restful-api on every server acting as a shadowsocks node.
Stop
cd ~/shadowsocks-hub
docker-compose stop
Restart
cd ~/shadowsocks-hub
docker-compose restart
Usage
Admin
Once logged in as the admin, the menu looks like:

The admin may choose to navigate to:
-
Managing servers. A
serveris a machine acting as a shadowsocks exit point. Aservermay have more than onenode. Admin has to provide its IP address or domain name when adding aserver. Admin may add, edit, and delete aserver. Note that aservercannot be deleted if anodehas been created using thisserver. Admin has to delete all itsnodesbefore successfully deleting theserver.The admin may also check and navigate to any
nodes,accounts, orusersusing aserver, and check totaltrafficthat aserverhas served.
-
Managing nodes. A
nodeis a virtual shadowsocks exit point. The difference betweenserverandnodeis that aserveris an indpendent machine where anodeis a logical machine whose functionality relies onserver. There can be multiplenodesresiding on a singleserver. From users' perspective,nodesusing the sameserverare different shadowsocks exit points. Before adding anode, the underlyingserverhas to be added into the system first. When adding a newnode, the admin has to select a server, give it a descriptive name, and provide its managing port, and managing password. Admin may also edit and delete anode. Note that anodecannot be deleted if anaccounthas been created using thisnode. Admin has to delete all itsaccountsbefore successfully deleting thenode.The admin may also check and navigate to the
serverthat anodebelongs to, anyaccountsorusersusing anode, and check totaltrafficthat anodehas serverd.
-
Managing products. A
productis a shadowsocks service subscription. When adding a newproduct, the admin has to give it a descriptive name, select a period of subscription, and provide traffic allowance for the period. The admin may also edit and delete aproduct. Note that aproductcannot be deleted if arequesthas been created on thisproduct(regardless of whether therequestis aproved or not).The admin may also check and navigate to any
accounts,users, orrequestsrelating to aproduct.
-
Managing users. A
useris a person using the shadowsocks service provided. The system is not open for registration, due to its nature of internal use. A newuserhas to be added by the admin into the system. When adding a newuser, the admin has to provide an email and initial password. The admin may also edit and delete auser. Note that ausercannot be deleted if arequesthas been created for this thisuser(regardless of whether therequestis aproved or not).The admin may also check and navigate to any
accounts,requests,products,nodes, orserversrelating to auser.
-
Managing requests. A
requestis made by the admin for auseron aproduct, or is made by auseron aproduct. Before making arequest, its underlyinguserandproducthave been added into the system. It requests for a shadowsocks service. The admin may choose to approve arequest. Upon approval, the system will create oneaccounton everynodethat the system has. Theseaccountswill allow theuserto use the specified shadowsocks service. Theaccountinformation will be shown when theuserlogin the system.The admin may also check and navigate to any
accounts,product, oruser, and check totaltrafficrelating to arequest.
-
Managing accounts. An
accountis a shadowsocks account containing all information needed for itsuserto use the shadowsocks service. The admin may manually add a newaccountby selecting auserand arequest. Before adding anaccount, its underlyinguserandrequesthave to be added into the system first. The admin may also delete anaccount. Note that anaccountcannot be deleted iftrafficinformation of theaccounthas been created by the system.The admin may also check and navigate to the
server,node,product,user,request, and check totaltrafficrelating to anaccount. In addition, the admin may choose to show a QR code encoding the account information.
Users
Once logged in as a user, the menu looks like:

A user may choose to navigate to:
-
Showing their accounts. A
usercheck the latesttrafficof any of their ownaccounts. They may also get the QR code displayed for any of theiraccounts.
-
Showing all products. A
usermay choose the make arequeston aproduct. Once arequestis created, it has to be approved by the admin beforeaccountscreated by the system.
-
Showing their requests. A
usermay check and navigate to anyaccounts, and check thetrafficrelating to arequest.
Rate limit
You may enforce a rate limit by setting the maximum number of requests allowed within 15-minute window from the same ip address. Requests exceeding the limit will be refused with HTTP status code 429 Too Many Requests. This setting can be done by add the following config to the .env file.
RATE_LIMIT = 50
Change the number to your choice.
Bug report, feature request, and feedback
Bug report, feature request, and feedback is welcome. Bugs have a high priority to get addressed. Feature requests and improvement feedback will be considered depending on their popularity and importance.