Networking HowTos
Networking HowTos

How To Disable root Logins Over SSH on CentOS

March 8, 2012 CentOS, Linux

Most Linux distributions allow the root user to connect in via SSH, and CentOS is no exception. It is recommended that root logins are never used, and you should use either su or sudo to elevate the permissions of a normal user account. As such, the best option is to disable root logins in the SSH server configuration file.
Note: these commands should be run as a user with root privileges (sudo or su), or from the console as root.
Open the /etc/ssh/sshd_config file in your editor of choice (vi in this example):

# vi /etc/ssh/sshd_config

There should be a line containing the following:

#PermitRootLogin yes

Edit this to read:

PermitRootLogin no

(Make sure you un-comment the line too)
Save the file and exit the editor.
Restart the SSH server:

# service sshd restart

or

# /etc/init.d/sshd restart

Root logins over SSH should now be disabled.

You Might Also Like