How to Disable Password Authentication for SSH

If you are already set up to login to your Linux server using SSH key authentication, you can increase the security of your server by disabling password authentication. To disable password authentication for SSH, do the following:

1sudo nano /etc/ssh/sshd_config

Set the following settings, or change them to “no” if they already exist:

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

Save the file and restart the ssh server:

1sudo systemctl restart sshd.service

Or on older non-systemd distros:

1/etc/init.d/sshd restart