Ubuntu

Login As Root on Ubuntu

The root user is not active on Ubuntu by default. It can be activated by setting its password using the passwd command and then using the su – command you can log in as root.

A root user is a user that possesses all the administrative privileges without any restrictions. It can access and modify any file, add or remove users, install or delete software, and change the system configurations.

The root user is distinct from a normal user, possessing the highest privileges and significantly more power. For example, a root user can perform critical commands and edit the system files without any restrictions, on the other hand, a normal user does not have such permissions.

In this guide, I will be exploring the Ubuntu root user, how to log in as a root user, and how it is different from a normal user.

Note: For the instructions and commands mentioned in this guide, I am using Ubuntu 22.04.

Ubuntu Root User

On installation of Ubuntu, a root user is created with no password. The root user is kept inactive to avoid any unintentional damage to the system files. Therefore, whenever you log in to your Ubuntu system, you enter as a normal user with specific provisions. However, that does not indicate you will be unable to access root privileges. If you have administrative privileges, then adding sudo before the commands allows you to execute root-specific commands.

Root Vs Sudo

Root is an account with all the privileges, while Sudo is a command line tool that allows a normal user with special privileges to run commands that require root powers. For example, when you perform a system-related command on Ubuntu, it gives you permission denied errors. This implies that you don’t have the authority to make those changes.

But when as a normal sudo user, you insert sudo before the command, it executes with absolutely no issue.

However, if you are working as a root user on your system, you don’t need to add sudo before the command to perform a system-related task.

To run the sudo command, a normal user must be granted administrative rights; refer to our guide on adding a user to sudoers on Ubuntu for more details.

Enable Root User on Ubuntu

As discussed earlier, the root user is locked on Ubuntu and its flavors. However, you can enable it by setting a password for the root user.

Note that, if you are not a part of sudoers, then you cannot perform these steps.

You can enable the root user using the passwd command with root as the username.

sudo passwd root

After executing the command, set a strong password, keeping in mind the significance of the root user. Once the password is set, the root user is enabled and can be accessed.

Login as Root

To log in as root on Ubuntu, open the terminal and use the su command with a dash , -l, or –-login option.

su -

You will be prompted with the password; type the password, and now you are logged in as root on Ubuntu.

Note that the typical $ sign of the bash shell is changed to the # sign when you log in as root on Ubuntu.

Now, you don’t need to put sudo while executing system-related commands or accessing system files.

To get back as a normal user, use the exit or logout command.

Login as Root through the Display Manager

The above method will work on the terminal only, however, if you want to use the display manager to log in as root on Ubuntu, that can also be done.

Warning: This method is not recommended because you can potentially lose server control in the case of a malicious attack. It is also possible that you cause harm to system files while installing software from an unknown source.

Note that the following instructions are for Ubuntu 22.04 with a GENOME desktop environment, and will not work if you are not using GENOME.

The latest GENOME uses the GDM3 display manager by default, so we will access the GDM3 configuration file using the nano text editor.

sudo nano /etc/gdm3/custom.conf

Type the following line in the file.

AllowRoot=true

Now, press ctrl+x to quit the file and save the changes.

The next step involves the modification of the PAM or Pluggable Authentication Module directory, which has a GDM password file.

Warning: The modification with errors can potentially corrupt the pam.d configuration files, which can ultimately make your server inaccessible.

Open the gdm-passowrd file again using the nano editor.

sudo nano /etc/pam.d/gdm-password

Comment out the highlighted line in the above screenshot using the # sign.

Press ctrl+x to quit and save the file.

Now, proceed to reboot the Ubuntu system, and then on the login screen select the Not Listed option.

Enter the username root and password that was created in the Login as Root section.

After login, open the terminal, and you will see the # sign by default.

Login as Root using Sudo

If you are a normal user and a part of the admin group or have superuser privileges (sudoer), then you can log in as a root user using the sudo command.

sudo -s

Or

sudo -i

After executing the above command, you will be prompted with the password input, enter your password (user password not root).

The username will be changed from your normal name to root; use the whoami command to know the current username.

whoami

Before login as root, the username is sam, but after login as root, the username is changed to root.

There are always security risks associated with active root users. So, I would recommend accessing root user privileges using the sudo command.

Conclusion

A root user is the top-level user with all the permissions, however, on Ubuntu the root user is not active by default. To activate the root user, a password needed to be set using the passwd command. If a user is already a sudoer then that user can become root using sudo -i command. This guide also mentioned a method to enable root login from GUI, which is not recommended. It is essential to note that including Ubuntu in many Linux distributions, the root user is kept inactive due to security risks. It is recommended to use sudo instead of logging in as an active root user because it is a safer option. To learn more about su and sudo use the man su and man sudo commands in the terminal.

About the author

Sam U

I am a professional graphics designer with over 6 years of experience. Currently doing research in virtual reality, augmented reality and mixed reality.
I hardly watch movies but love to read tech related books and articles.