Edit /etc/ssh/sshd_config

vim /etc/ssh/sshd_config

Add the DenyUsers directive

DenyUsers user1 user2

Or add the AllowUsers directive

PermitRootLogin no
AllowUsers user1 user2
PasswordAuthentication yes

Resstart the SSH daemon

sudo systemctl restart sshd

or

sudo systemd restart sshd