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

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?

The root user is the superuser or administrator with elevated privileges, enabling them to execute commands and make changes to the system that regular users cannot. The root user has unrestricted access to all files and commands, making it a powerful but potentially risky account. 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.

4 Steps to Create 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:

1. Create a New User

You can create a new user from the terminal using the adduser command. Check the below steps to see how it works:

  1. First, open your terminal by pressing CTRL+ALT+T.
  2. Type the following command:

    adduser abir
    EXPLANATION
    • adduser: Adds a new user
    • abir: Creates a new user named abir.
    user cannot be added without using sudo command
  3. You have to be a root user to execute the adduser command. You can easily do this by using this command:
    sudo adduser abir

    Here the sudo command grants administrative privileges.

    Create a New User using sudo command

  4. 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

  5. Finally, you can check whether the user has been created or not by typing the following command.
    getent passwd | grep abir
    EXPLANATION
    • getent: Looks into the administrative database that is given as its argument.
    • passwd: Contains user information.
    • Pipe (|): Redirects the standard output.
    • grep: Looks for a specific pattern given to it as an argument.

    New account created in ubuntu

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

2. 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. To add your newly created user “abir” to the sudo group type the following command:

sudo usermod -aG sudo abir
EXPLANATION
  • usermod: Modifies an existing user account.
  • -aG: Adds a user to the specific group.
To check whether the user is added to the group, type the groups abir command.

Add User to the Sudo Group You can see in the above picture that abir is added to the sudo group.

3. 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:

  1. Type the following command:
    su - abir
  2. Type your password and you will be in the new user’s shell as shown in the below picture.switch user
  3. Now, type sudo visudo command to open the sudoers file in your nano text editor.
  4. Go to the user privilege specification line and replace the username with root.
  5. Save the file by pressing CTRL+ X and then the Y buttons.
  6. Press the ENTER button. Your user privileges will be set.
    replacing root user with new user in nano text editor
  7. Finally, to check the user privileges you can just type the sudo whoami command.
    checking the current userIt shows that you are the root user of this machine.


4. 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:

sudo passwd root

First, you need to give your user password and then set the new password for the root.Changing password to log in as a root user

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.

To log in as a root user in Ubuntu by various methods. Here are some of the useful ones for your better understanding:

1. Using the “sudo” command

To log in as a root user you can just type the below command:

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

2. Using the “su” command

You can log in as a root user by just typing the below command:

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



3. Using the “sudo su” command

If you want to log in as a root user you can just type the below command:

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

4. Using the “sudo su -” command

By typing the below command you can log in as a root user:

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 -

5. Using the “sudo -i” command

You can use the sudo -i command to log in as a root user. 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



6. Using the “sudo -s” command

Run the sudo -s command to log in as a root user. 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:

  1. First, open the Ubuntu Terminal.
  2. Type the sudo whoami command in the command prompt.
  3. Now, press the ENTER button.
    Another user softeko is not a root userHow to Create Root User in Ubuntu

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

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 used for?

The root user is used for performing critical system-level tasks, such as installing or removing software, configuring system settings, and managing user accounts. This elevated level of access allows the root user to make changes that can impact the entire system, making it a powerful but potentially risky account.

It is recommended to use the root user account judiciously to minimize the risk of unintended system alterations.

What is the difference between a root user and a normal user?

The root user and a normal user differ in their levels of system privileges. The root user, also known as the superuser or administrator, has unrestricted access to all files and commands on a computer. This user can modify system-critical files, install software, and perform administrative tasks.

In contrast, a normal user has limited access and can only modify files and settings within their designated user space. Root access is typically required for system-wide changes, while normal users operate within predefined boundaries to ensure system security and stability.

How do you know if a user is a root user in Linux?

To determine if a user is a root user in Linux, you can check their user ID (UID). The root user typically has a UID of 0. Use the id -u command in the terminal. If the output is 0, the user is the root user; otherwise, they are not.

How do I find the root user in Linux?

To find the root user in Linux, you can use the whoami command. This command will display the current username, and if you are the root user, it will output “root.”

Alternatively, 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?

The root user in Linux is necessary for:

  • Managing user accounts and configuring system settings.
  • Installing or removing software that requires system-wide changes.
  • Performing operations on protected files and directories.
  • Creating, modifying, or deleting user accounts.
  • Conducting system updates, backups, and resolving critical issues.

Use the root user in Linux when:

  • Installing or removing software that requires system-wide changes.
  • Configuring system settings and making adjustments that impact the entire system.
  • Performing file system operations like creating, deleting, or modifying protected files and directories.
  • Managing user accounts, including creating, modifying, or deleting accounts.
  • Conducting system maintenance tasks such as updates, backups, and resolving critical system-related issues.

Why log in as a root user?

Root account provides full system access for crucial operations, enabling modifications, software installations, and configuration changes. However, frequent use poses serious risks, including potential errors or malicious activities. To enhance system stability and security, it is recommended to avoid regular root account usage and perform tasks with limited privileges.

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 System user

What is the difference between root and sudo user?

The root user and the sudo user serve distinct purposes in Unix-like operating systems:

Root User Sudo User
  • Highest system access.
  • Elevated privileges for specific tasks.
  • Direct access to all.
  • Requires password for entering.
  • Riskier for routine tasks.
  • Safer for routine tasks, minimizing potential system damage

Relaed Articles

5/5 - (7 votes)
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
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