How to disable SSH login for the root user?

A dedicated web server is one of the best options for those websites who are facing downtime and loading issues on their website. And by using the dedicated solution you will also get more advantages and in dedicated solution, it offers the capabilities and resources of an entire server to one business or website where you will not be share any of your resources with others websites. So today websites which deal with high traffic or looking for any customization with security then choosing dedicated server are one of the best options.

Currently, if you are using a dedicated hosting server for your website and if you are looking for information on how to SSH login for the root user then here is the solution. So today if you are having a good and strong password you can limit your exposure from any sorts of attacks on your website. But sometime some people will try to sneak into your hosting service by having the root permission of your server. So to overcome these security threats you can disable the SSH login for the root user.

Follow the below steps to disable SSH login for the root user in the server:

>> Log into your SSH

>> Now you have to add the user by following the below command-

[root@root ~]# adduser demo

[root@root ~]# id demo

uid=10018(demo) gid=10018(demo) groups=10018(demo)

[root@root ~]# ls -lad /home/demo/

drwx------ 2 demo demo 4096 April 10 04:01 /home/demo/

>> Once you have added a user, now you have to create a password for that user. Follow this-

[root@root ~]# passwd demo

Changing password for user demo.

New UNIX password:

Retype new UNIX password:

passwd: all authentication tokens updated successfully.

[root@root ~]#

>> And now you have to give the sudo permission for your new user to access the file as the root user. So follow the below command-

[root@root ~]# echo 'demo ALL=(ALL) ALL' >> /etc/sudoers

>> Now login with the new username and password via SSH and you have to see that your logging and that account is working fine.

[root@root ~]# ssh This email address is being protected from spambots. You need JavaScript enabled to view it.

This email address is being protected from spambots. You need JavaScript enabled to view it.'s password:


>> Now you have to check that you switch the users to the root by an admin user.  

[demo@admin~]$ su -


[root@root ~]$ thisisme


>> And now to disable the root SSH login you need to edit it here- /etc/ssh/sshd_config with your favorite text editor.  

[root@root ~]# vi /etc/ssh/sshd_config and you have to change this to

#PermitRootLogin yes    ----  Change it to-

PermitRootLogin no

>> Once you are done, now login to the server by this command

[root@root ~]# /etc/init.d/sshd restart

Stopping sshd: [ OK ]

Starting sshd: [ OK ]

[root@root ~]#

>> Now you will be able to connect to your server via SSH by using admin user and next you have to use su command to switch the root user.