How to Enable Root Login via SSH in Ubuntu

In Ubuntu, root login via SSH is disabled by default for security reasons. Enabling it can be useful for certain administrative tasks, but it also makes your system more vulnerable to unauthorized access. Follow these steps carefully to enable and, if desired, disable root login after completing your tasks.


Step 1: Enable the Root Account

Ubuntu locks the root account by default, which means no password is set. Before enabling SSH root login, you need to set a password for the root user.


  1. Log in to the server: Access your Ubuntu server as a user with sudo privileges.

  2.  Set the root password: Run the following command to set a password for the root user:


sudo passwd root




  1. Confirm the password: Enter and confirm the new password when prompted. This unlocks the root account and sets the specified password.


Step 2: Modify SSH Configuration to Permit Root Login

Now, adjust the SSH configuration to allow root login.

  1. Open the SSH configuration file:


sudo nano /etc/ssh/sshd_config




  1. Locate the PermitRootLogin setting:

  • Find the line that starts with PermitRootLogin. This line may have a value like prohibit-password, no, or it might be commented out with a #.

  1. Change the setting:

  • To enable root login, modify the line to:
              


PermitRootLogin yes



  • If the line is commented out (e.g., # PermitRootLogin no), remove the # symbol to uncomment it.

  • Save and exit: In nano, press CTRL + X, then Y to confirm, and hit Enter to save.


Step 3: Restart SSH Service

After modifying the SSH configuration, restart the SSH service to apply the changes.



sudo systemctl restart ssh





Step 4: Test Root SSH Login

Now that root login is enabled, test it to ensure it's working as expected.

  1. Log in as root: On your local machine, run the following command, replacing with your server's IP address:


ssh root@




  1. Enter the root password: When prompted, enter the root password you set in Step1. 


If configured correctly, you should now be able to log in as root.


Important: Re-Disable Root Login for Security

Once you've completed the necessary tasks, it's highly recommended to disable root login to reduce security risks.

  1. Reopen the SSH configuration file:


sudo nano /etc/ssh/sshd_config



  1. Set PermitRootLogin to No:


PermitRootLogin no




  1. Restart the SSH service:


sudo systemctl restart ssh




By re-disabling root login, you make it harder for unauthorized users to access your system.


Was this answer helpful? #1 #1
 

Did We Miss Out on Something?

Relax, we have you covered. At Go4hosting, we go the extra mile to keep our customers satisfied. We are always looking out for opportunities to offer our customers “extra” with every service. Contact our technical helpdesk and we’d be more than happy to assist you with your Cloud hosting, Colocation Server, VPS hosting, dedicated Server or reseller hosting setup. Get in touch with us and we’d cover all your hosting needs, however bizarre they might be.

Submit your Query

  • I'm not a robot

Browse by ServicesBrowse by Services

Resource Library

What is Cloud Computing

Understand the term cloud computing, the ongoing trend, its playing field, future growth and how industry...

Myths about Cloud Computing

Cloud computing, in the recent years, has become a subject of significant discussion among the industry experts.

Download Now

Did We Miss Out on Something?

Relax, we have you covered. At Go4hosting, we go the extra mile to keep our customers satisfied. We are always looking out for opportunities to offer our customers “extra” with every service. Contact our technical helpdesk and we’d be more than happy to assist you with your Cloud hosting, Colocation Server, VPS hosting, dedicated Server or reseller hosting setup. Get in touch with us and we’d cover all your hosting needs, however bizarre they might be.

Submit Query

Please fill in the form below and we will contact you within 24 hours.