How to disable root ssh logins on CentOS 7

If you have a server that’s available over a network it’s generally a good idea to disable root access over ssh.

The reason for this, is that, scripts run attempting to access  your server and these scripts use the root username to try and log in. A simple way to protect yourself is to simply disable root access via SSH.

We will first create a standard user account that we’ll use to administer our system.

Run the command:

useradd darren

Next we’ll set a password for the user

passwd darren

Now let’s give the account admin permissions:

visudo

Add the following line to the file:

darren = ALL=(ALL) ALL

Now lets stop root from accessing the server via ssh:

vi /etc/ssh/sshd_config

Edit the line:

PermitRootLogin yes

To make it read:

PermitRootLogin no

 

Now restart SSH:

service sshd restart.

Next make sure your you can ssh into the account you created:

ssh darren@192.168.123.67

Run a command with sudo to insure you have sudo access

sudo ls

Once you have confirmed you can exit the server knowing that root access is now disabled for the server.

 

 

 

 

 

 

1 thought on “How to disable root ssh logins on CentOS 7

  1. Pingback: How to Disable Root SSH Access on CentOS 7 | Host your Website

Leave a Reply

Your email address will not be published. Required fields are marked *