This tutorial will guide you through enabling or disabling SSH access for specific users or groups by modifying the default SSH configuration file.
Step 1: Enable SSH Access for a Specific User or Group
To begin, log in to your VPS as the root user or a user with sudo privileges.
1.1 Allow SSH Access for a Specific User
To grant SSH access to a particular user (e.g., test), edit the sshd_config file:
sudo vi /etc/ssh/sshd_config
1.2 Enter Insert Mode and Modify the Configuration
Press i to enter insert mode and add or edit the following line:

Note: Ensure there's a space between "AllowUsers" and "test." It's recommended to use the Tab key after typing "AllowUsers" to insert the correct spacing.
1.3 Allow SSH Access for Multiple Users
To allow multiple users to access SSH, list their usernames separated by spaces:

1.4 Allow SSH Access for a Specific Group
To allow an entire group, such as root, modify the following line:

This change will allow all users within the "root" group to connect to the server via SSH.
1.5 Apply the Changes
After editing and saving the SSH configuration file, restart the SSH service to apply the changes:
sudo systemctl restart sshd
If a user not listed tries to log in, they will receive the following message:

Step 2: Disable SSH Access for a Specific User or Group
2.1 Deny SSH Access for a Specific User
To block SSH access for a specific user (e.g., test1), edit the sshd_config file:
sudo vi /etc/ssh/sshd_config
2.2 Modify the Configuration to Deny Access
Add or modify the following line:

2.3 Deny SSH Access for Multiple Users
To block SSH access for multiple users, list their usernames separated by spaces:

2.4 Deny SSH Access for a Specific Group
To block SSH access for an entire group (e.g., root), add the following line:

2.5 Apply the Changes
After saving these changes, restart the SSH service:
sudo systemctl restart sshd
Now blocked users our groups will not be able to log in to the server via SSH.