Disable Password Authentication on CentOS, Ubuntu & Linux

In this chapter, you will learn

  1. How to disable Password-based authentication on Ubuntu, Centos, and Other Linux Distribution?

After you set up SSH key-based authentication on your server, it's time to disable password-based authentication to add an extra layer of security. Disabling password-based authentication is simple. You just need to change the PasswordAuthentication no in the sshd.config file.

How to Disable PasswordAuthentication?

Ubuntu/CentOS

Step 1: Login to your server.
Step 2: Type following command to open sshd.config file.
sudo vi /etc/ssh/sshd_config
Step 3: Press i to enter into Insert mode.
Step 4: Search for following line and edit them as follows and remove # tag from beginning if found.
ChallengeResponseAuthentication no PasswordAuthentication no UsePAM no
Step 5: To save and exit, press Esc → type :wq → Press Enter.
Step 6: Restart SSH server.
Ubuntu
sudo systemctl restart ssh.service

or,

sudo service ssh restart
Centos:
sudo systemctl restart sshd.service

Summary

In this tutorial, you learned how to disable password-based authentication on Ubuntu/CentOS servers. It's a good practice to enable SSH key-based login and disable password login.