Edit the SSH Configuration File
Open the main configuration file using a text editor like nano with administrative privileges
sudo nano /etc/ssh/sshd_config
Add the Deny Directive
Scroll to the bottom of the file and add the DenyUsers directive followed by the username you want to block
DenyUsers username_to_block
Restart the SSH Service
Save the file (press Ctrl+O then Enter in nano) and exit (Ctrl+X). Test your configuration for errors, then restart the service to apply the changes
sudo sshd -t
sudo systemctl restart ssh
Alternative: The Whitelist Approach
If you prefer to block everyone by default and only allow a few specific users, use AllowUsers instead
AllowUsers allowed_user1 allowed_user2
Top comments (0)