In a previous article titled Configuring SSH Access on Ubuntu, we discussed how to set up SSH access on Ubuntu. In this article, we will continue by explaining how to allow access using the root user.
Start by accessing the remote server where you want to enable root access. Log in using the standard or basic user that was set up in the previous article, in my case, aldrass.
ssh aldrassOnce inside, open the SSH configuration file located at /etc/ssh/sshd_config using your preferred text editor.
sudo nano /etc/ssh/sshd_configOnce there, look for the property called PermitRootLogin. This line is usually commented out, meaning it starts with a #symbol. Remove the # symbol and set the value to yes, resulting in the following:
PermitRootLogin yesThe second step is to enable password authentication. Why do we do this? We need to copy the public key from our machine to the root user’s .ssh directory, but we’ll cover that later. For now, in the same configuration file /etc/ssh/sshd_config, locate the property PasswordAuthentication and update its value to yes, resulting in the following:
PasswordAuthentication yesNow, save the file and restart the SSH service.
service sshd restartThe next step is to set a password for the root user. How do we do this? Execute the following command:
sudo passwd rootSpecify your preferred password and confirm it.
Now we are ready to copy the public key from our local machine to the server. To do this, execute the following command. Note that in my case, the key is ~/.ssh/id_rsa.pub, but it might be different for you.
ssh-copy-id -i ~/.ssh/id_rsa.pub root@ironforgeNow that the key has been transferred to the server, we just need to disable password authentication. To do this, on the server, reopen the file /etc/ssh/sshd_config, locate the property PasswordAuthentication, and set it to no. Save the changes and restart the SSH service using the command:
service sshd restartThe only thing left is to update the ~/.ssh/config file on our local machine to use the root user. This is how it is currently configured:
Host ironforge
HostName 192.168.128.2
user aldrass
IdentityFile ~/.ssh/id_rsaWe need to update the user to root, so it will look like this:
Host ironforge
HostName 192.168.128.2
user root
IdentityFile ~/.ssh/id_rsaFinally, you should now be able to access the server using the root user. If you try ssh ironforge and enter the root password you set earlier, you will be able to access the server.
If you made it to the end and successfully completed the tutorial, congratulations!
Yuniel Alvarez



