How to Create a Root User in Ubuntu [Step-by-Step]

The root user is the supreme user in a Linux operating system. It has access to everything on the machine and can do any tasks and open any files. To execute any administrative work in Linux you need to be the root user.  In this article, I will show you how to create a root user in Ubuntu with different methods.

What is a Root User in Ubuntu?

Root user refers to the supreme user who has access over literally everything in a system. In Linux, any user ID assigned with entity ‘0’ is the root user. It can read, write and perform any operation on the system as the superuser.

Summary

You can easily create a root user in Ubuntu by following 5 simple steps and they are:

  • First, create a new user by using the adduser
  • Then, add the newly created user to the sudo group by using the usermod
  • Now, review the newly created user who is actually being added to the sudo group.
  • Look over the sudo access of the newly created sudo user.
  • Finally, log in as a root user using sudo and su

Watch Steps of Creating a Root User in Ubuntu

Steps of Creating a Root User in Ubuntu

In the following example, I will create a root user in Ubuntu named “abir”. I have illustrated the full process in the following 4 steps.

Step 01: Create a New User

You can create a new user from the terminal using the adduser command. Type the following command in the Ubuntu terminal.

adduser abir

user cannot be added without using sudo command

You have to be a root user to execute the adduser command. It can easily be done by prefixing the sudo command and then providing the user password.

sudo adduser abir

Create a New User using sudo command

Now, provide a password for the newly created user and retype it. Here, You can skip the data-filling step by pressing the ENTER button each time and finally press Y to confirm.

Create a New User in Ubuntu

Finally, you can check whether the user has been created or not by typing the following command.

getent passwd | grep abir

You can see in the below picture that a new user named abir has been created.

New account created in ubuntu

Step 02: Add User to the Sudo Group to Create a Root User

Adding a user to this sudo group means this user will now possess privileged powers.

Now, to add your newly created user “abir” to the sudo group type the following command on your Ubuntu Terminal.

sudo usermod -aG sudo abir

To check whether the user is added to the group, type the following command:

groups abir

You can see in the below picture that abir is added to the sudo group.

Add User to the Sudo Group

Step 03: Verify User privileges to Create a Root User

To verify user privileges for my newly created user abir, I need to switch to that user from my current one. To do so type the following command on your Ubuntu Terminal.

su - abir

Type your password and you will be in the new user’s shell as shown in the below picture.

switch user

Now, type another command in your Ubuntu Terminal to open sudoers file in your nano text editor.

sudo visudo

Go to the user privilege specification line and replace the username with root.

Save the file by pressing CTRL+ X and then the Y buttons.

Press the ENTER button. Your user privileges will be set.

replacing root user with new user in nano text editor

Finally, to check the user privileges you can just type the following command.

sudo whoami

This will show you that you are the root user of this machine as shown in the below picture.

checking the current user



Step 04: Log in as a Root User in Ubuntu

Before logging in as a root user, you need to change the root password to get access. To do so you just type the following command in the Ubuntu Terminal.

sudo passwd root

First, you need to give your user password and then set the new password for the root.

You can see in the below picture that the password has been updated successfully. Now you can log in to the machine as a root user at any time by giving this password.

Changing password to log in as a root user

You can log in as a root user in Ubuntu by various methods. Here I have given most of the useful ones for your better understanding. You can use any of these to log in.

A. Create a Root User by Using the “sudo” command

To log in as a root user you can just type the below command in your Ubuntu Terminal.

sudo bash

After pressing the ENTER button, you will see that your command prompt and terminal will change as shown in the below picture. I am the root user of this machine.

How to Create Root User in Ubuntu using sudo command

B. Create a Root User by Using the “su” command

To log in as a root user you can just type the below command in your Ubuntu Terminal.

su -

After pressing the ENTER button, you will see that your command prompt and terminal will change as shown in the below picture. I am the root user of this machine.

log in as a root user using su - command



C. Using the “sudo su” command

To log in as a root user you can just type the below command in your Ubuntu Terminal.

sudo su

After pressing the ENTER button, you will see that your command prompt and terminal will change as shown in the below picture. I am the root user of this machine now.

How to Create Root User in Ubuntu using sudo su

D. Using the “sudo su -” command

To log in as a root user you can just type the below command in your Ubuntu Terminal.

sudo su -

After pressing the ENTER button, you will see that your command prompt and terminal will change as shown in the below picture. Now I am the root user of this machine.

How to Create Root User in Ubuntu using sudo su -

E. Using the “sudo -i” command

To log in as a root user you can just type the below command in your Ubuntu Terminal.

sudo -i

After pressing the ENTER button, you will see that your command prompt and terminal will change as shown in the below picture. Now I am the root user of this machine.

How to Create Root User in Ubuntu using sudo -i



F. Using the “sudo -s” command

To log in as a root user you can just type the below command in your Ubuntu Terminal.

sudo -s

After pressing the ENTER button, you will see that your command prompt and terminal will change as shown in the below picture. Now I am the root user of this machine.

How to Create Root User in Ubuntu using sudo -s

Check If a User is a Root User in Ubuntu

I have shown you how to create a root user in Ubuntu. Now, you can inspect whether a user is a root user or not by using the following process.

Steps to Follow >

➊ First, open the Ubuntu Terminal.

➋ Type the following command in the command prompt:

sudo whoami

➌ Now, press the ENTER button.

Output >

In the following image, I have examined two users named “softeko” & “abir” respectively. Between them, softeko is not a root user but abir is a root user.

Another user softeko is not a root user

How to Create Root User in Ubuntu

Conclusion

The root user can read, write and perform any operation on the system as the superuser. Hence, It is very important to create a root user and do any administrative job to change the inside and outside environment of the machine while needed. After completing this article, you will be able to create a root user in Ubuntu.

People Also Ask

What is the root user in Linux?
Root user refers to the supreme user who has access over literally everything in a system. In Linux, any user ID assigned with entity ‘0’ is the root user. It can read, write and perform any operation on the system as the superuser.
What is the root user used for?
The root user can access to all the commands and files in Linux. The root user can read, write and perform any operation on the system as the superuser.
What is the difference between a root user and a normal user?
A root user has all the power to do anything on the machine. But a normal user is assigned some particular files and commands. As a regular user, you cannot perform all the tasks and are prevented from doing anything that is administrative.
How do you know if a user is a root user in Linux?
The root user’s UID is always assigned with entity ‘0’. You can also check the user ID or the logged-in username by executing the whoami command in your Ubuntu Terminal.
How do I find the root user in Linux?
You can find the root user in Linux by executing the cat etc/passwd command in your Ubuntu Terminal. This will open a file containing the list of all users. In that list, you will find the root user on your machine.
Is a root user the same as the admin?
Yes, the root user in Linux is the same as the admin. In fact, the root user is the admin of the operating system who can do any kind of administrative job without anyone’s interruption.
Why do we need a root user and when to use it?
We need a root user to perform administrative tasks. Normal users can not do these. We use it when we need to do tasks that are not allowed to do by the general users.
Why log in as a root user?
To execute any commands or to work with any file that can not be done by the general user in Linux. Logging in as a root user gives you access to every file and command in the machine.
What are the 3 types of users in Linux?
There are primarily three kinds of users in Linux based on their permission privileges. They are 1) The Regular user, 2) the Root user & 3) the Service user.
What is the difference between root and sudo user?
A sudo user can perform privileged tasks by adding sudo in the command every time. However, the root user is the supreme user and the privileged one. It doesn’t require prefixing sudo every time.

Relaed Articles

5/5 - (4 votes)
Borhan Uddin

Hello, I am Borhan Uddin, a resident of Dhaka, Bangladesh. I have completed my undergraduate degree in Electrical and Electronic Engineering (EEE) from Chittagong University of Engineering and Technology (CUET). I love to spend my leisure by playing and watching various movies & dramas. Currently, I am working as a Linux Content Developer Executive here. I would like to learn more about Linux every day of the week and would be keen to share it with you rapidly. Read Full Bio

Leave a Comment