SSH on Ubuntu is by default configured in a way that disables the root users log in. Originally this is enabled as a security measure which means that you cannot directly log in as the root user over SSH. However, you can easily use the Root SSH login via Sudo command. But, in some conditions, it is more convenient to directly logged in as root.
Steps to enable Root login over SSH
1) Login to your server as root.
2) Now you are a root user. So, edit the sshd_config file located in /etc/ssh/sshd_config
vim /etc/ssh/sshd_config
3) Now, add the following command to the file. Even though you can add it anywhere but we advise you to follow the best practice by adding the command in the block for authentication.
PermitRootLogin yes
4) Save this file and exit.
5) Restart your SSH server using the following command :
systemctl restart sshd
Or
service sshd restart
That’s it.
With this, the new line gets added and the SSH server gets restart, this allows you now to connect via the root user.
In this instance, you will be able to log in as the root user by using either the password or an SSH key.
If you use SSH keys, you will be able to set the PermitRootLogin value to ‘without-password’ instead of yes. To complete this, just modify step 2 with the following command :
PermitRootLogin without-password
This process works on all versions of the Linux server on which the sshd service is installed. In case you are using a cPanel server, still you can easily control this setting from the WHM interface. In such cases, we recommend you to modify this setting from your control panel interface.
Also Read :
How to Set Up SSH Keys on Ubuntu 18.04