How to log in as root in Ubuntu

On many of the most popular Linux distributions, including Ubuntu, it’s possible to log into your computer as a “root” user. The root user is one of the highest possible types of accounts you can use on any desktop or laptop that runs Linux. Consider it like the primary administrator. You’ll get full administrative privileges on the entire system for editing configuration files and accomplishing other common tasks. It’s not turned on by default, though, and will require some extra work. So, we’re here to help with a look at how to unlock the root account and log in with it.



We would advise against unlocking access to the root account, if possible. Tasks performed under root can severely damage your computer. There are other ways to access certain features of a Linux system, including SuperUser DO.


Unlock the Root account

To begin this process, we need to unlock the root account first. This requires using the terminal. Here’s how:

  1. Open Terminal.
  2. Enter the following command and the password for your account.
    sudo passwd root
    A screenshot of the proccess for starting a root account on Ubuntu

  3. Enter a new root user password. (This has to be at least six characters long.)
  4. To disable the root account, run the following command:
    sudo passwd -l root

That’s it! You’ve just enabled the root account and root access on Ubuntu. There are still some extra steps to take, however, before you get to the login screen.


Understanding how to run commands as the root user in the terminal

Provided you unlocked the root account, you can now use the terminal as root. Dive in with the steps below:

  1. Open Terminal.
  2. Run the following command:
    su -
  3. Enter the root password created in prior steps. You’ll know you’re root in the terminal when you see the command line ends with # instead of the usual $.
    A screenshot of a temrinal session on Ubuntu with root commands active

  4. Type any command that you’d like to use.

Each time you want to run a command as root, be sure to use the su – command to trigger the root session.

Enable the root login in the GUI

Now that you’ve enabled root and know how it works in the terminal, we can go ahead and enable the root login in the GUI if you want to use it in a desktop environment. We do not recommend doing this, but if you want to, this will require you to go through some extra steps in the terminal once again.


  1. Open Terminal.
  2. Run the following command:
    su -
  3. Enter the root password created in prior steps.
  4. Run the following command:
    sudo nano /etc/gdm3/custom.conf
  5. Scroll up the list using your keyboard.
  6. Add a new line below TimedLoginDelay = 10.
  7. Enter the text AllowRoot=True.
    A screenshot of confirming a change to the user configuration file in Ubuntu to add root access

  8. Press Ctrl +X to commit the change and save the file.
  9. Press Y.
  10. Run the following command:
    sudo nano /etc/pam.d/gdm-password
  11. On the third line of the text, where it says auth required pam_succeed_If, insert a # to begin the line. The text should look like what we have below.
    A screenshot of one of the commands needed in the Ubuntu terminal for enabling the root access in Ubuntu

  12. The line will turn blue. Press Crtl + X to save it.

You can now close all open windows and return to the Ubuntu Login screen.


Log in as root on Ubuntu through the login screen

With all those steps completed, you’ve now reached the end! You can finally log in as root through Ubuntu’s login screen. Check it out with the steps below:

  1. Choose Not listed.
  2. In the Username field, enter root.
    A screenshot of the Ubuntu login page showing root as the user name

  3. In the Password field, enter the root password you created earlier.
    A screenshot of the warning message on Ubuntu about authentication and a privilege user being logged in

You’ll know you’re logged in as root because you’ll see Ubuntu give you a warning message at the top of your desktop about privileged users.

A last resort

There’s a reason why the root account is hidden in Linux, and it’s primarily because tasks for root are usually for emergency repairs and restoring lost accounts. You shouldn’t mess around with the root if you don’t need to. But if you do need to, now you can. We would recommend doing this on a virtual machine or system not running a live environment with sensitive data, which will allow you to break and fix as many things as possible, learning moire about what makes Linux a powerful operating system.


[ad_2]

Related posts