Skip to content

How to log in as Ubuntu root

Rate this post

How to log in as Ubuntu root: After reading my guide on how to install Ubuntu , you decided to venture into the Linux world and you were fascinated by the many things that can be done with this operating system. You will have noticed, however, that certain operations require you to enter your account password to complete them.

This happens because Ubuntu protects system files and applications from accidental changes, so as to keep the system stable. But if you really want to get your hands down, even if entering your password is not enough, how should you do it? The answer is to log in as Ubuntu root , ie enable the account that has super administrator rights (the “root” one, in fact) and act through the latter.

In today’s tutorial I will explain how to do it but, mind you, it is a highly discouraged procedure, as it allows, as already said, to put “your hands” in points of the system that could compromise the correct functioning of the same. In light of this, I take no responsibility for any damage done to the system after implementing it. Clear? All right, then I’d say we can ban the talk and take action. I will use Ubuntu 18.04 for the tutorial , but the indications in the guide should also be valid for the older and probably future editions of the distro (as long as they use the GDM display manager at least). Happy reading and good luck for everything!

How to log in as root in Ubuntu

How to log in as Ubuntu root

If you want to learn how to log in as Ubuntu root , the first step you need to take is to start the Terminal included in the operating system. If you do not know how to access the latter, click on the grid icon located at the bottom of the left sidebar, search for “terminal” in the screen that opens (using the appropriate search field at the top) and select Terminal icon (the command line) from the results.

Ubuntu terminal

At this point, in the Terminal window that opened, type the command sudo passwd rootand press the Enter key on your PC keyboard, in order to set a password for the Ubuntu root account. You will first have to enter the password of your personal account (the one with which you are currently logged in) and then the one to be used to log in as root (twice in a row).

At the end of the operation, if everything went in the right direction, the message password updated will appear correctly .

Ubuntu root password

Now, you need to allow the root account to be usable on the Ubuntu logon screen. To do this, go back to the Terminal and issue the following commands.

  • sudo passwd -u rootto unlock the root user. The command should return the phrase “passwd: password expiry information changed” as a result.
  • sudo nano /etc/gdm3/custom.conf to edit the GDM configuration file, Ubuntu’s default display manager.

A text editor will open directly in the Terminal, in which you will have to go to action by pasting the string # AllowRoot=trueunder the wording [security]. So you’ll have to get something like this.

[security]

# AllowRoot=true

To save the changes and close the file, press the key combinations Ctrl + O (to save the file, then confirm by pressing the Enter key ) and Ctrl + X (to close the editor).

How to log in as Ubuntu root

Now, once you are back in the “main section” of the Terminal, you have to give other commands.

  • sudo nano /etc/pam.d/gdm-password to edit another GDM configuration file, Ubuntu’s default display manager.

In this case too, the text editor will open, through which you will have to go to act by adding the symbol #at the beginning of the string auth required pam_succeed_if.so user != root quiet_successplaced under the wording #%PAM-1.0. So you’ll have to get something like this.

#%PAM-1.0

auth requisite pam_nologin.so (line that should already be present in the file)

#auth required pam_succeed_if.so user != root quiet_success

To save the changes and close the file, press the key combinations Ctrl + O and Ctrl + X on your PC keyboard.

How to log in as Ubuntu root

Finally, you have to go back to the Terminal and give one last command.

  • sudo nano /root/.profile, to edit the “.profile” file through the editor from Terminal.

Now you have to go to modify the string mesg n || trueso that it becomes tty -s && mesg n || true. Eventually you will have to get something like this.

# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

fi

tty -s && mesg n || true

How to log in as Ubuntu root

To save the changes, as usual, press the key combinations Ctrl + O and Ctrl + X on your PC keyboard.

More is done! To log in as root on Ubuntu, you just have to restart your computer and wait for the operating system logon screen to appear.

Then click on the item Not listed? , type the term root in the Username field that appears on the screen and, after pressing the Enter key on your PC keyboard, enter the login password for the root account that you previously set in the Terminal. If you’ve done everything correctly, the Ubuntu desktop will load and you will be logged in as root connected to the operating system.

Ubuntu root desk

If the logon screen does not appear when you start your Ubuntu but you are automatically logged into the system using the standard account, end the work session by clicking on the shutdown button in the bar at the top right and you will be redirected to the login screen.

In case of second thoughts, you can retrace your steps and disable the ability to log in as root in Ubuntu by opening the Terminal and going to remove the changes made previously.

  • sudo nano /etc/gdm3/custom.confto clear the string # AllowRoot=true.
  • sudo nano /etc/pam.d/gdm-passwordto delete the symbol #at the beginning of the string auth required pam_succeed_if.so user != root quiet_success.
  • sudo nano /root/.profileto restore the string tty -s && mesg n || truein mesg n || true.

Alternative procedure (old versions of Ubuntu)

Ubuntu root on old versions

If you are using an older version of Ubuntu, in which the LightDM display manager is used , you can activate root access by following a slightly different procedure.

  • Access the Terminal by calling it from the main distro menu;
  • Type the command sudo passwd rootand first enter the password of the account you are currently using and then the one you want to use to log in as root (twice in a row).
  • Type the command sudo sh -c ‘echo "greeter-show-manual-login=true" >> /etc/lightdm/lightdm.conf’to allow root user access through the Ubuntu logon screen.

Mission accomplished! Now you just have to restart the computer, click on the Log in item in the Ubuntu logon screen, type the term root in the text field below and, after pressing the Enter key , log in as root by entering the password you have set first in the Terminal.

In case of doubts or problems, I remind you that you can count on the official Ubuntu Italia forum , which allows you to get very useful support and advice on the use of the distro in question by all members of the community (which is increasingly large ). You will not struggle to find an answer to your questions, I guarantee you!