1
0
mirror of synced 2024-11-28 15:56:01 +03:00
setup-ipsec-vpn/docs/manage-users.md

186 lines
6.0 KiB
Markdown
Raw Normal View History

2022-07-29 07:55:47 +03:00
[English](manage-users.md) | [中文](manage-users-zh.md)
2016-06-08 04:10:57 +03:00
2022-07-29 07:55:47 +03:00
# Manage VPN Users
2016-06-08 04:10:57 +03:00
2022-09-11 08:54:45 +03:00
By default, a single user account for VPN login is created. If you wish to view or manage users for the IPsec/L2TP and IPsec/XAuth ("Cisco IPsec") modes, read this document. For IKEv2, see [Manage IKEv2 clients](ikev2-howto.md#manage-ikev2-clients).
2016-06-08 04:10:57 +03:00
2021-06-06 23:27:56 +03:00
* [Manage VPN users using helper scripts](#manage-vpn-users-using-helper-scripts)
2022-03-15 06:13:10 +03:00
* [View VPN users](#view-vpn-users)
* [View or update the IPsec PSK](#view-or-update-the-ipsec-psk)
2021-06-06 23:27:56 +03:00
* [Manually manage VPN users](#manually-manage-vpn-users)
2020-12-07 10:11:23 +03:00
## Manage VPN users using helper scripts
2022-09-11 08:54:45 +03:00
You may use helper scripts to add, delete or update VPN users for both IPsec/L2TP and IPsec/XAuth ("Cisco IPsec") modes. For IKEv2, see [Manage IKEv2 clients](ikev2-howto.md#manage-ikev2-clients).
2016-06-08 04:10:57 +03:00
2022-03-13 23:42:04 +03:00
**Note:** Replace command arguments below with your own values. VPN users are stored in `/etc/ppp/chap-secrets` and `/etc/ipsec.d/passwd`. The scripts will backup these files before making changes, with `.old-date-time` suffix.
2016-06-08 04:10:57 +03:00
2018-11-23 20:52:38 +03:00
### Add or edit a VPN user
2020-12-07 10:11:23 +03:00
Add a new VPN user, or update an existing VPN user with a new password.
2016-06-08 04:10:57 +03:00
2022-05-15 23:07:23 +03:00
Run the [helper script](../extras/add_vpn_user.sh) and follow the prompts:
2022-03-13 23:42:04 +03:00
```bash
sudo addvpnuser.sh
```
<details>
<summary>
Error: "sudo: addvpnuser.sh: command not found".
</summary>
This is normal if you used an older version of the VPN setup script. First, download the helper script:
2016-06-08 04:10:57 +03:00
```bash
2022-05-21 03:07:55 +03:00
wget https://get.vpnsetup.net/adduser -O /opt/src/addvpnuser.sh
2022-03-13 23:42:04 +03:00
chmod +x /opt/src/addvpnuser.sh && ln -s /opt/src/addvpnuser.sh /usr/bin
```
2022-03-13 23:42:04 +03:00
Then run the script using the instructions.
</details>
2021-12-31 01:03:25 +03:00
Alternatively, you can run the script with arguments:
```bash
# All values MUST be placed inside 'single quotes'
# DO NOT use these special characters within values: \ " '
2022-03-13 23:42:04 +03:00
sudo addvpnuser.sh 'username_to_add' 'password'
2020-12-07 10:11:23 +03:00
# OR
2022-03-13 23:42:04 +03:00
sudo addvpnuser.sh 'username_to_update' 'new_password'
2016-06-08 04:10:57 +03:00
```
### Delete a VPN user
2016-06-08 04:10:57 +03:00
Delete the specified VPN user.
2016-06-08 04:10:57 +03:00
2022-05-15 23:07:23 +03:00
Run the [helper script](../extras/del_vpn_user.sh) and follow the prompts:
2022-03-13 23:42:04 +03:00
2016-06-08 04:10:57 +03:00
```bash
2022-03-13 23:42:04 +03:00
sudo delvpnuser.sh
```
2022-03-13 23:42:04 +03:00
<details>
<summary>
Error: "sudo: delvpnuser.sh: command not found".
</summary>
This is normal if you used an older version of the VPN setup script. First, download the helper script:
```bash
2022-05-21 03:07:55 +03:00
wget https://get.vpnsetup.net/deluser -O /opt/src/delvpnuser.sh
2022-03-13 23:42:04 +03:00
chmod +x /opt/src/delvpnuser.sh && ln -s /opt/src/delvpnuser.sh /usr/bin
```
Then run the script using the instructions.
</details>
2021-12-31 01:03:25 +03:00
Alternatively, you can run the script with arguments:
```bash
# All values MUST be placed inside 'single quotes'
# DO NOT use these special characters within values: \ " '
2022-03-13 23:42:04 +03:00
sudo delvpnuser.sh 'username_to_delete'
2016-06-08 04:10:57 +03:00
```
### Update all VPN users
2016-06-08 04:10:57 +03:00
2022-05-15 23:07:23 +03:00
Remove **all existing VPN users** and replace with the list of users you specify.
2022-05-15 23:07:23 +03:00
First, download the [helper script](../extras/update_vpn_users.sh):
2022-03-13 23:42:04 +03:00
```bash
2022-10-15 07:35:22 +03:00
wget https://get.vpnsetup.net/updateusers -O updateusers.sh
```
2022-05-15 23:07:23 +03:00
**Important:** This script will remove **all existing VPN users** and replace with the list of users you specify. Therefore, you must include any existing user(s) you want to keep in the variables below.
2022-05-15 23:07:23 +03:00
To use this script, choose one of the following options:
**Option 1:** Edit the script and enter VPN user details:
```bash
2022-10-15 07:35:22 +03:00
nano -w updateusers.sh
[Replace with your own values: YOUR_USERNAMES and YOUR_PASSWORDS]
2022-10-15 07:35:22 +03:00
sudo bash updateusers.sh
```
**Option 2:** Define VPN user details as environment variables:
```bash
# List of VPN usernames and passwords, separated by spaces
# All values MUST be placed inside 'single quotes'
# DO NOT use these special characters within values: \ " '
sudo \
VPN_USERS='username1 username2 ...' \
VPN_PASSWORDS='password1 password2 ...' \
2022-10-15 07:35:22 +03:00
bash updateusers.sh
```
2022-03-15 06:13:10 +03:00
## View VPN users
By default, the VPN setup scripts will create the same VPN user for both IPsec/L2TP and IPsec/XAuth ("Cisco IPsec") modes.
For IPsec/L2TP, VPN users are specified in `/etc/ppp/chap-secrets`. The format of this file is:
```bash
"username1" l2tpd "password1" *
"username2" l2tpd "password2" *
... ...
```
For IPsec/XAuth ("Cisco IPsec"), VPN users are specified in `/etc/ipsec.d/passwd`. Passwords in this file are salted and hashed. See [Manually manage VPN users](#manually-manage-vpn-users) for more details.
## View or update the IPsec PSK
The IPsec PSK (pre-shared key) is stored in `/etc/ipsec.secrets`. All VPN users will share the same IPsec PSK. The format of this file is:
```bash
%any %any : PSK "your_ipsec_pre_shared_key"
```
To change to a new PSK, just edit this file. DO NOT use these special characters within values: `\ " '`
You must restart services when finished:
```bash
service ipsec restart
service xl2tpd restart
```
2020-12-07 10:11:23 +03:00
## Manually manage VPN users
2021-06-04 22:48:19 +03:00
For IPsec/L2TP, VPN users are specified in `/etc/ppp/chap-secrets`. The format of this file is:
```bash
2018-11-23 20:52:38 +03:00
"username1" l2tpd "password1" *
"username2" l2tpd "password2" *
... ...
```
You can add more users, use one line for each user. DO NOT use these special characters within values: `\ " '`
2021-06-04 22:48:19 +03:00
For IPsec/XAuth ("Cisco IPsec"), VPN users are specified in `/etc/ipsec.d/passwd`. The format of this file is:
```bash
2018-11-23 20:52:38 +03:00
username1:password1hashed:xauth-psk
username2:password2hashed:xauth-psk
... ...
```
Passwords in this file are salted and hashed. This step can be done using e.g. the `openssl` utility:
```bash
2018-11-23 20:52:38 +03:00
# The output will be password1hashed
# Put your password inside 'single quotes'
openssl passwd -1 'password1'
```
2021-03-29 23:05:45 +03:00
## License
2023-01-05 03:58:29 +03:00
Copyright (C) 2016-2023 [Lin Song](https://github.com/hwdsl2) [![View my profile on LinkedIn](https://static.licdn.com/scds/common/u/img/webpromo/btn_viewmy_160x25.png)](https://www.linkedin.com/in/linsongui)
2021-03-29 23:05:45 +03:00
2021-06-05 01:27:21 +03:00
[![Creative Commons License](https://i.creativecommons.org/l/by-sa/3.0/88x31.png)](http://creativecommons.org/licenses/by-sa/3.0/)
This work is licensed under the [Creative Commons Attribution-ShareAlike 3.0 Unported License](http://creativecommons.org/licenses/by-sa/3.0/)
2021-03-29 23:05:45 +03:00
Attribution required: please include my name in any derivative and let me know how you have improved it!