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
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
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.
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.
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.
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.
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.
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.
- How to Create a Jenkins User on Ubuntu? [2 Methods]
- How to Create MySQL User in Ubuntu? [2 Cases]
- Create User Without Home Directory in Ubuntu in Just 3 Steps
- How to Create a User in Docker Container Without Docker File?
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.
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.
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.
- How to Create an FTP User in Ubuntu? [Step-by-Step]
- Create a New SFTP User in Ubuntu with a New SSH Key
- How to Create Group and Add User in Ubuntu? [2 Cases]
- Create FTP User for Specific Directory in Ubuntu [4 Steps]
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.
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.
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 Multiple Users in Linux? [2 Methods]
- Create a User in Ubuntu as Read-Only Access to Log Folder
- How to Create User Account in Ubuntu with Public Key
- Create A User in Ubuntu that Runs a Script and Logs Out [4 Steps]
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.
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.
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
Relaed Articles
- How to Create User and Add to Sudo in Ubuntu? [2 Methods]
- 2 Ways to Create a User With Access to a Drive in Ubuntu
- How to Create a New User in Ubuntu by GUI? [Step-by-Step]
- 2 Ways to Create User Account in Ubuntu Using Terminal
- How to Create Home Directory for Existing User in Ubuntu
- Create User with UID and GID in Ubuntu? [3 Scenarios]
- How to Create a Sudo User in Ubuntu? [Step-by-Step]