How to disable SSH login for the root user?
A dedicated 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 server you will also get more advantages and in dedicated server hosting 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 dedicated server:
>> Log into your SSH
>> Now you have to add the user by following the below command-
[[email protected] ~]# adduser demo
[[email protected] ~]# id demo
uid=10018(demo) gid=10018(demo) groups=10018(demo)
[[email protected] ~]# 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-
[[email protected] ~]# passwd demo
Changing password for user demo.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[[email protected] ~]#
>> 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-
[[email protected] ~]# 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.
>> Now you have to check that you switch the users to the root by an admin user.
[[email protected]~]$ su -
[[email protected] ~]$ thisisme
>> And now to disable the root SSH login you need to edit it here- /etc/ssh/sshd_config with your favorite text editor.
[[email protected] ~]# vi /etc/ssh/sshd_config and you have to change this to
#PermitRootLogin yes ---- Change it to-
>> Once you are done, now login to the server by this command
[[email protected] ~]# /etc/init.d/sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
[[email protected] ~]#
>> 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.