Quick Links
-
Understanding how to run commands as the root user in the terminal
-
Enable the root login in the GUI
-
Log in as root on Ubuntu through the login screen
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
Accessing the root account is different from using SuDo. To begin this process, we need to unlock the root account first. This requires using the terminal. Here’s how:
- Open Terminal.
- Enter the following command and the password for your account.
sudo passwd root
- Enter a new root user password. (This has to be at least six characters long.)
- 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:
- Open Terminal.
- Run the following command:
su -
- 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 $.
- Type any command that you’d like to use.
Each time you want to run a command as root, be sure to use the are – 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 thisbut if you want to, this will require you to go through some extra steps in the terminal once again.
- Open Terminal.
- Run the following command:
su -
- Enter the root password created in prior steps.
- Run the following command:
sudo nano /etc/gdm3/custom.conf
- Scroll up the list using your keyboard.
- Add a new line below TimedLoginDelay=10.
- Enter the text AllowRoot=True.
- Press Ctrl +X to commit the change and save the file.
- Press Y.
- Run the following command:
sudo nano /etc/pam.d/gdm-password
- 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.
- 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:
- Choose Not listed.
- In the Username field, enter root.
- In the Password field, enter the root password you created earlier.
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.
Only use root as 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.