Disable root login and password authentication in Linux

WARNING!: Before following the steps below, make sure you have either physical access to the machine or you have setup access via SSH Private/Public Key to that machine, otherwise you will be locked out!

Disable root SSH login

You need edit the sshd_config file to look for the variable PermitRootLogin and change it from yes to no then save the file, exit and restart sshd service.

# Edit sshd_config file
sudo nano /etc/ssh/sshd_config

# Restart SSHD for changes to take effect
sudo systemctl restart sshd

Disable password authentication via SSH for any user

You need edit the sshd_config file to look for the variable PasswordAuthentication and change it from yes to no then save the file, exit and restart sshd service.

# Edit sshd_config file again
sudo nano /etc/ssh/sshd_config

# Restart SSHD for changes to take effect
sudo systemctl restart sshd