To allow *specific users* to log in using SSH and *restrict others* in a Linux system, you can configure the `/etc/ssh/sshd_config` file. Here's how to do it:
1. *Edit the SSH Configuration File*
Open the SSH configuration file (`/etc/ssh/sshd_config`) in a text editor, such as `nano` or `vim`:
```bash
sudo nano /etc/ssh/sshd_config
```
2. *Allow Specific User(s)*
To allow only certain users to log in via SSH, use the `AllowUsers` directive. Add the usernames of the users you want to allow:
```bash
AllowUsers user1 user2
```
Replace `user1` and `user2` with the actual usernames you want to allow.
3. *Deny All Other Users (Optional)*
You can explicitly deny all users and then allow specific ones by adding the `DenyUsers` directive as well. For example:
```bash
DenyUsers
AllowUsers user1 user2
```
This configuration denies SSH access to everyone except `user1` and `user2`.
4. **Save and Exit the SSH Config File*
After making the necessary changes, save and exit the file:
In `nano`, press *Ctrl + O* to save, and *Ctrl + X* to exit.
5. *Restart the SSH Service*
For the changes to take effect, restart the SSH service:
```bash
sudo systemctl restart sshd
```
6. *Test the Configuration*
Test SSH login for the allowed users:
```bash
ssh user1@hostname
```
Other users will be denied access based on the configuration.
7. *Optional: Allow Specific Group*
If you want to allow a group of users rather than individual ones, you can use the `AllowGroups` directive:
```bash
AllowGroups sshusers
```
This allows only members of the `sshusers` group to log in via SSH.
Summary:
*`AllowUsers`* specifies which users are allowed to log in via SSH.
*`DenyUsers`* can be used to deny access to specific users.
After making changes, restart the SSH service with `systemctl restart sshd` to apply the new settings.
This is a good way to control which users can access the system remotely via SSH, increasing security by restricting access.