When using V2Ray for proxy Internet access, you may want to share your VPS with your family, friends, and colleagues. Sharing a server with multiple people eliminates the cost of deploying multiple servers and maximizes the utilization of your VPS.
To achieve that, you need to configure multi-user support for your V2Ray server.
V2Ray has a flexible architecture that allows us to configure multiple clients (users) on the server side, and each user uses a different UUID. This not only allows multiple users to connect to and use a single server, but also facilitates management.
The following is how to configure V2Ray for multi-user use.
First, make sure you have a VPS that has successfully installed V2Ray. If you need a tutorial, please refer to this article.
Then open the V2Ray server configuration file for editing. Use the following command.
vi /usr/local/etc/v2ray/config.json
Before editing the configuration file, let's review the single-user configuration. Below is a relatively basic single-user configuration.
{ "inbounds": [ { "port": 8000, "protocol": "vmess", "settings": { "clients": [ { "id": "a1111111-1111-1111-1111-111111111111", "alterId": 0 } ] } } ], "outbounds": [ { "protocol": "freedom", "settings": {} } ] }
To achieve multi-user use, you need to modify the code in the inbounds section and add new clients.
The following introduces two different multi-user configuration methods.
The first one is suitable if you plan to share your V2Ray server with your family members, and the number of people is not large. Use the following configuration.
{ "inbounds": [ { "port": 8000, "protocol": "vmess", "settings": { "clients": [ { "id": "a1111111-1111-1111-1111-111111111111", "alterId": 0, }, { "id": "b2222222-2222-2222-2222-222222222222", "alterId": 0, }, { "id": "c3333333-3333-3333-3333-333333333333", "alterId": 0, } ] } } ], "outbounds": [ { "protocol": "freedom", "settings": {} } ] }
Explanation:
- Each client corresponds to a user, with id and alterId.
- id is the user's unique UUID. You need to replace the id shown in the above example with UUID generated by yourself, you can use the command
uuidgen
to generate it. - It is recommended to set alterId to 0 (currently V2Ray officially recommends this setting).
In this configuration, we added multiple new user information to clients, including id and alterId, and all users use the same port. The advantage of this is that it is relatively simple and does not require the addition and management of other ports, which can fully meet the needs of yourself and your family.
What if the people you want to share are not your family, but are friends, classmates, colleagues, or other people, how should you configure it? These people are likely watching a lot of video content and consuming a lot of data transfer, which your VPS provider has limits on. In this case, we need to use the second configuration method, that is, add new ports to the inbounds section in the configuration file and assign each user to a different port. Once a user's data transfer exceeds the limit, you can set a limit on the port assigned to him or her. When a large number of users share your VPS, different users using different ports will make it easier for you to manage, for example, you can more easily view each user's different Internet access records.
Edit the configuration file as shown below.
{ "inbounds": [ { "port": 8000, "protocol": "vmess", "settings": { "clients": [ { "id": "a1111111-1111-1111-1111-111111111111", "alterId": 0, "email": "[email protected]" } ] } }, { "port": 8001, "protocol": "vmess", "settings": { "clients": [ { "id": "b2222222-2222-2222-2222-222222222222", "alterId": 0, "email": "[email protected]" } ] } }, { "port": 8002, "protocol": "vmess", "settings": { "clients": [ { "id": "c3333333-3333-3333-3333-333333333333", "alterId": 0, "email": "[email protected]" } ] } } ], "outbounds": [ { "protocol": "freedom", "settings": {} } ] }
Explanation:
The email field is used to mark the user's identity. You don't need to use real email addresses. You can omit this field if you don't care about the user's identity.
After saving the configuration file (enter :wq
and press Enter), restart V2Ray to apply the changes:
systemctl restart v2ray
Check whether the service is running normally:
systemctl status v2ray
In addition, if your VPS uses a firewall, you need to open the ports used in the configuration file. The command to open the port is:
ufw allow 8001 (replace with the actual port number)
Once the configuration is complete, you can send each user's UUID, port information, and IP of the server to them, and let them download the V2Ray client app (such as V2RayN, V2RayNG) and use that information to connect to your V2Ray server.