Manual Steps to disable SSH login for root user
1) Create a new sudo user
Log in as root via SSH.
Add a new user using the following command:
adduser newusername
Set the password of the new username:
passwd newusername
Add the user to the wheel group (this gives sudo access on CentOS/CloudLinux/AlmaLinux/Rocky Linux/RHEL):
usermod -aG wheel newusername
Verify sudo privileges:
su - newusername
Try a sudo command:
sudo whoami
It should return root.
2. Disable root login over SSH
Edit the SSH config file:
nano /etc/ssh/sshd_config
Find and modify or add the following line:
PermitRootLogin no
Also ensure:
PasswordAuthentication yes # If you're using password login (optional)
Restart SSH service:
systemctl restart sshd
Important: Keep your current SSH session open while testing the new user’s login in a second terminal. If anything fails, you can still revert.