How to Disable Password Login in CentOS7

One option is the following: In CentOS7, you can disable password login by modifying the SSH configuration file. Here are the specific steps:

  1. Login to the system with the root user.
  2. Open the SSH configuration file /etc/ssh/sshd_config using vim or another text editor.
sudo vim /etc/ssh/sshd_config
  1. Locate the following two lines of code within the file:
#PasswordAuthentication yes
#PermitRootLogin yes

Change these two lines of code to:

PasswordAuthentication no
PermitRootLogin no
  1. Save the file and exit the editor.
  2. Restart the SSH service to apply the configuration changes.
sudo systemctl restart sshd

Password login has been disabled, so you can only use SSH keys to authenticate when logging into the CentOS7 system.

bannerAds