Disable root login for SSH on Ubuntu:


Edit this file:
sudo nano /etc/ssh/sshd_config

Replace:
#PermitRootLogin prohibit-password
with:
PermitRootLogin no

Save with Ctrl+X

Then lock the root user by:
sudo passwd root -ld

*Also lock these users while at it:
sudo passwd games -ld
sudo passwd news -ld
sudo passwd www-data -ld
sudo passwd mail -ld

Can see if a user is locked by if the /etc/shadow file has a ! for the user rather then a * or a password.

Then restart OpenSSH server by:
sudo systemctl restart ssh


You should no longer be able to access root.


Source 1 | Source 2 | Date: April 19th 2024


Back

© 2019 to 2025 Branden Gilfoil & © up to 2025 for respective owners.