In this tutorial, we will learn about how to set root password in Ubuntu. In Linux distributions, there are multiple user accounts created, each having its own password. This is required to segregate the work of one user from another. For example, let’s say we have created two user account “vnfm” and “stack”. Each user will have its own password configured. So, vnfm user will not be able to access any data owned by stack user and vice-versa unless the access is given exclusively.
There is always a super user in any Linux distribution which will have all the system access, including access to all the suer accounts created in a system. This user is known as super user or root user. In many cases, we require the root access. To switch as root user, we must know its password. We will learn about different method to set the root user password in Ubuntu in the upcoming sections of this tutorial. So, let’s begin.
Ubuntu is one of the most popular Linux distribution operating system based on Debian. It is an open source tool which means anyone can find the source code of it and can install on computers, servers or on any other devices. It offers many features to its end user like user-friendly interface, which is accessible to users, Debian package manager which is used to install packages and many more features.
How to Set Root Password in Ubuntu
Also read: What does Bash set -e Flag Means in Script ?
In Ubuntu, by default root user is locked due to security concerns. But as we discussed earlier in this tutorial, we can always set the password of root user and use it. We will talk about 3 common methods to set the root password in Ubuntu operating system.
- Ubuntu operating system installed.
- Login user must have sudo privilege.
Method-1: Using ‘sudo’ Command.
In this method, we will set the root user password using sudo command. Open the terminal, you will be logged in as default user. Next, type below command to set the root user password. When you execute below command first time for the current terminal session, it will prompt you for the current user password. After authenticating the current user, it will prompt you for the new root user password as shown below.
[stack@linuxnasa ~] $ sudo passwd root [sudo] password for stack: Changing password for user root. New password: passwd: password updated successfully.
Method-2: Enabling ‘root’ Account.
In this method, we will first switch to root user using the command sudo -i. When you execute the command for the first time in the current terminal session, it will prompt you to enter the password for current user as shown below.
[stack@linuxnasa ~] $ sudo -i [sudo] password for stack: [root@linuxnasa ~] #
Next, once you become root user, type the command ‘passwd‘ to set the root user password as shown below.
[root@linuxnasa ~] # passwd Changing password for user root. New password: Retype new password: passwd: all authentication tokens updated successfully.
Method-3: Switching to ‘root’ User.
Another method we can use is by switching to the root shell using the command ‘sudo -s‘. Once you become root user , use ‘passwd’ command to set the root user password as shown below.
[stack@linuxnasa ~] $ sudo -s [sudo] password for stack: [root@linuxnasa ~] $# passwd Changing password for user root. New password: Retype new password: passwd: all authentication tokens updated successfully.
We have learnt about different methods to set the super user or root user password in Ubuntu. Using the root user is not recommended when you work on production due to major security concerns. So, make sure you are using your local setup to practice the commands covered in this tutorial.