e Learning

How to Disable root ssh Login in Centos 7

You Can add extra security to a Linux Server By Disabling Remote Access to root User, So That Only Non Root Users can connect to the server via ssh. In this Article we will discuss how to disable root ssh login in Centos 7.

Disable root ssh Login

Here I Have A Linux Server With Centos 7 installed and with IP address 192.168.1.10. Currently the Server has Remote root login enabled and we are going to disabled it with Following Steps.

  1. Open sshd_config File with a text editor which is located at /etc/ssh Directory. I am Going to use Command Line Text Editor Vim.

    vim /etc/sshd/sshd_config

  2. Now Find and Uncomment, the line PermitRootLogin then change its value to “no”.

    PermitRootLogin no

  3. Now save changes and restart the ssh service with systemctl command.

    systemctl restart sshd.service

Now If we try to connect to the Centos7 Server remotely using root user, we will get an error message “Access denied” or “Permission denied, please try again” depending on the ssh client we use.

Permission denied, please try again

After You Disabled ssh root Login and if you want root privileges to the server from remote location, what you have to do is login as a regular user and then use su command to login as root user or you can always use sudo command while executing commands (to use sudo command you need sudo privileges, following article describe how to give sudo privileges to a regular user)

How to Give User sudo Access in Linux Centos 7