This tutorial will show you how to enable or disable SSH access for a user or group by making changes to the SSH default configuration file.
Prerequisites
Log in to your VPS as root or a user with sudo privileges.
1. Enable SSH Access for a Particular User or Group
1.1 Allow SSH Access for a Specific User
To allow SSH access for a particular user (e.g., test
), edit the sshd_config
file:
sudo vi /etc/ssh/sshd_config
Press "i" to enter insert mode and add or edit the following line:
Note: Ensure there is a space between "AllowUsers" and "test." Use the Tab key after typing "AllowUsers" to provide the username.
1.2 Allow SSH Access for Multiple Users
You can specify more than one user by adding their usernames:
1.3 Allow SSH Access for a Group
To allow an entire group (e.g., root
), add or modify the following line:
1.4 This will allow all users in the "root" group to connect via SSH.
1.5 Restart SSH Service
After saving the changes, restart the SSH service for the changes to take effect:
sudo systemctl restart sshd
If a non-allowed user tries to log in, they will receive the message:
2. Disable SSH Access for a User or Group
2.1 Deny SSH Access for a Specific User
To disable SSH access for a specific user (e.g., test1
), edit the sshd_config
file:
sudo vi /etc/ssh/sshd_config
2.2 Deny SSH Access for Multiple Users
To deny SSH access to multiple users, list the usernames separated by spaces:
2.3 Deny SSH Access for a Group
To disable SSH access for an entire group (e.g., root
), add the following line:
2.4 Restart SSH Service
After saving these changes, restart the SSH service:
sudo systemctl restart sshd
Blocked users or groups will no longer be able to log in to the server via SSH.
By following these steps, you can easily manage SSH access for specific users and groups on your VPS.