Root User in Ubuntu- Important Things You Should Know

Wondering how to become root user in Ubuntu? Here are some essential things you should know about the root user in Ubuntu.
Warp Terminal

How do you become a root user in Ubuntu?

Either you run commands with root privilege like this:

sudo any_command

Or you switch user in Ubuntu to root user like this:

sudo su

In both cases, you’ll have to enter your own user account’s password. But there’s more to root account in Ubuntu that you should know.

When you have just started using Linux, you’ll find many things that are different from Windows. One of those ‘different things’ is the concept of the root user.

In this beginner series, I’ll explain a few important things about the root user in Ubuntu.

Please keep in mind that while I am writing this from Ubuntu user’s perspective, it should be valid for most Linux distributions.

You’ll learn the following in this article:

  • Why root user is disabled in Ubuntu
  • Using commands as root
  • Switch to root user
  • Unlock the root user

What is root user? Why is it locked in Ubuntu?

Root User Ubuntu

In Linux, there is always a super user called root. This is the super admin account that can do anything and everything with the system. It can access any file and run any command on your Linux system.

With great power comes great responsibility. Root user gives you complete power over the system and hence it should be used with great caution. Root user can access system files and run commands to make changes to the system configuration. And hence, an incorrect command may destroy the system.

This is why Ubuntu and other Ubuntu-based distributions lock the root user by default to save you from accidental disasters.

You don’t need to have root privilege for your daily tasks like moving file in your home directory, downloading files from internet, creating documents etc.

Take this analogy for understanding it better. If you have to cut a fruit, you use a kitchen knife. If you have to cut down a tree, you have to use a saw. Now, you may use the saw to cut fruits but that’s not wise, is it?

Does this mean that you cannot be root in Ubuntu or use the system with root privileges? No, you can still have root access with the help of ‘sudo’ (explained in the next section).

📋
Bottom line: Root user is too powerful to be used for regular tasks. This is why it is not recommended to use root all the time. You can still run specific commands with root.

How to run commands as root user in Ubuntu?

Sudo Sandwich xkcd
Image Credit: xkcd

You’ll need root privileges for some system specific tasks. For example, if you want to update Ubuntu via command line, you cannot run the command as a regular user. It will give you permission denied error or show ‘are you root’ error.

apt update
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)

So, how do you run commands as root? The simple answer is to add sudo before the commands that require to be run as root.

sudo apt update

Ubuntu and many other Linux distributions use a special mechanism called sudo. Sudo is a program that controls access to running commands as root (or other users).

Sudo is actually quite a versatile tool. It can be configured to allow a user to run all commands as root. You may configure it run only a selected few commands as root. You can also configure to run sudo without password. It’s an extensive topic and maybe I’ll discuss it in details in another article.

For the moment, you should know that when you install Ubuntu, you are forced to create a user account. This user account works as the admin on your system and as per the default sudo policy in Ubuntu, it can run any command on your system with root privileges.

The thing with sudo is that running sudo doesn’t require root password but the user’s own password.

And this is why when you run a command with sudo, it asks for the password of the user who is running the sudo command:

abhishek@nuc:~$ sudo apt update
[sudo] password for abhishek: 

As you can see in the example above, user abhishek was trying to run the ‘apt update’ command with sudo and the system asked the password for abhishek.

If you are absolutely new to Linux, you might be surprised that when you start typing your password in the terminal, nothing happens on the screen. This is perfectly normal because as the default security feature, nothing is displayed on the screen. Not even the asterisks (*). You type your password and press enter.

📋
Bottom line: To run commands as root in Ubuntu, add sudo before the command. When asked for password, enter your account’s password. When you type the password on the screen, nothing is visible. Just keep on typing the password and press enter.

How to become root user in Ubuntu?

You can use sudo to run the commands as root. However, in situations, where you have to run several commands as root and you keep forgetting to add sudo before the commands, you may switch to root user temporarily.

The sudo command allows you to simulate a root login shell with this command:

sudo -i
abhishek@nuc:~$ sudo -i
[sudo] password for abhishek: 
root@nuc:~# whoami
root
root@nuc:~# 
💡
You’ll notice that when you switch to root, the shell command prompt changes from $ (dollar key sign) to # (pound key sign). This makes me crack a (lame) joke that pound is stronger than dollar.

Though I have shown you how to become the root user, I must warn you that you should avoid using the system as root. It’s discouraged for a reason after all.

You can use su command to switch users in Ubuntu. You can use it with sudo to temporarly switch to root user:

sudo su

If you try to use the su command without sudo, you’ll encounter ‘su authentication failure’ error.

You can go back to being the normal user by using the exit command.

exit

How to enable root user in Ubuntu?

By now, you know that the root user is locked by default in Ubuntu-based distributions.

Linux gives you the freedom to do whatever you want with your system. Unlocking the root user is one of those freedoms.

If, for some reason, you decide to enable the root user, you can do so by setting up a password for it:

sudo passwd root

Again, this is not recommended and I won’t encourage you to do that on your desktop. If you forget it, you won’t be able to change the root password in Ubuntu again.

You can lock the root user again by removing the password:

sudo passwd -dl root
How to Reset Forgotten Ubuntu Password in 2 Minutes
If you forgot your user password on Ubuntu, don’t worry. You can reset an Ubuntu password very easily. This guide explains an easy method for changing the root password on Ubuntu. The method should also be applicable to other Linux distributions.

In the end…

I hope you have a slightly better understanding of the root concept now. If you still have some confusion and questions about it, please let me know in the comments. I’ll try to answer your questions and might update the article as well.

About the author
Abhishek Prakash

Abhishek Prakash

Created It's FOSS 11 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries 🕵️‍♂️

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

itsfoss happy penguin

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.