How to disable SSH Password Authentication and Root Login for CentOS

When you've decided to connect to your server via SSH key rather than the password, you would need to disable password authentication to require all users connecting via SSH to use key authentication. Next, you’ll disable root login to prevent the root user from logging in via SSH. These steps are optional, but are strongly recommended.
Here’s how to disable SSH password authentication and root login:
Open the SSH configuration file for editing by entering the following command:

sudo nano /etc/ssh/sshd_config

Change the PasswordAuthentication setting to no as shown below. Verify that the line is uncommented by removing the # in front of the line, if there is one:

PasswordAuthentication no

Change the PermitRootLogin setting to no as shown below:

PermitRootLogin no

Save the changes to the SSH configuration file by pressing Control-X, and then Y.

Restart the SSH service to load the new configuration. Enter the following command:

sudo systemctl restart sshd

After the SSH service restarts, the SSH configuration changes will be applied.

  • 128 Users Found This Useful
Was this answer helpful?

Related Articles

FFMPEG install on CentOS

How to install FFMPEG and FFMPEG-PHP install on CentOS 5.X To install FFMPEG please follow the...

How to set hostname on Centos 6?

In order to permanently set hostname on Centos 6 VPS you neew to run # nano...

How to change hostname on CentOS permanently

If you are installing LAMP on a new server and ran into the following issue with httpd during the...

CentOS: Start custom script automatically after network startup

Find the ifup-post under /etc/sysconfig/network-scripts. This scipt is called right after any...

Change hostname in CentOS

How to Change Hostname - CentOSThis KB helps user to change hostname on CentOS. By default your...