<\/span><\/h2>\r\n\r\n\r\n\r\nDisable SSH Root Login in CentOS 7In order to disable the root login, we need to modify the main ssh configuration file “sshd_config” with a text editor of your choice. In our example, we will use nano as an editor.<\/p>\r\n\r\n\r\n\r\n
nano \/etc\/ssh\/sshd_config<\/pre>\r\n\r\n\r\n\r\nNow search for this line below in the file.<\/p>\r\n\r\n\r\n\r\n
#PermitRootLogin no<\/pre>\r\n\r\n\r\n\r\nUncomment the line by removing the ‘#’ from the beginning of the line. The line in the file should look like this:<\/p>\r\n\r\n\r\n\r\n
PermitRootLogin no<\/pre>\r\n\r\n\r\n\r\nBy executing the following command we will restart the SSH daemon service:<\/p>\r\n\r\n\r\n\r\n
systemctl restart sshd.service<\/pre>\r\n\r\n\r\n\r\nNow when we try to log in as the root user, you should get an “Access Denied<\/strong>” error.<\/p>\r\n\r\n\r\n\r\nlogin as: root\r\nroot@Server_IP_Address password:\r\nAccess denied\r\nroot@Server_IP_Address password:<\/pre>\r\n\r\n\r\n\r\nAt this point, you are not able to log in directly as root, but you can still log in as a normal user with sudo privileges and use ‘sudo’ or ‘su’ command to switch to the root user. For example:<\/p>\r\n\r\n\r\n\r\n
login as: username\r\nusername@Server_IP_Address password:\r\nLast login: Wed Sep 26 12:11:38 2018 from IP_address\r\n[username@hostname ~]$ su -\r\nPassword:\r\nLast login: Thu Sep 27 11:05:19 CDT 2018 from IP_address on pts\/1\r\n[root@hostname ~]#<\/pre>\r\n\r\n\r\n\r\n<\/span>Enable SSH Root Login<\/span><\/h2>\r\n\r\n\r\n\r\n\r\n
\r\nEnable SSH Root Login CentOS 7<\/figcaption>\r\n<\/figure>\r\n<\/div>\r\n\r\n\r\n\r\nIn order to enable logging in as root, we need to modify the main ssh configuration file \u00a0“sshd_config” with a text editor of your choice. In our example, we will use nano as an editor.<\/p>\r\n\r\n\r\n\r\n
nano \/etc\/ssh\/sshd_config<\/pre>\r\n\r\n\r\n\r\nFind the following line in the file.<\/p>\r\n\r\n\r\n\r\n
PermitRootLogin no<\/pre>\r\n\r\n\r\n\r\nComment the line out by adding a ‘#’ at the beginning of the line, or change ‘no’ to ‘yes’ like in the examples shown below.<\/p>\r\n\r\n\r\n\r\n
#PermitRootLogin no<\/pre>\r\n\r\n\r\n\r\nor<\/p>\r\n\r\n\r\n\r\n
PermitRootLogin yes<\/pre>\r\n\r\n\r\n\r\nAfter we save the file we should restart the sshd service.<\/p>\r\n\r\n\r\n\r\n
systemctl restart sshd.service<\/pre>\r\n\r\n\r\n\r\nYou can now try to log in directly as a root user.<\/p>\r\n\r\n\r\n\r\n
login as: root\r\nroot@Server_IP_Address password:\r\nLast login: Wed Sep 27 12:22:50 2018 from IP_address\r\n[root@hostname ~]#<\/pre>\r\n\r\n\r\n\r\n