Set, reset and change the root password in Ubuntu 20.04
The root user is nothing but the default user created in Linux system with administrative privileges. Similar to older Ubuntu versions, the root user is locked in Ubuntu 20.04, and a user can never log in as root initially. The system of using the command
sudo is used instead, which allows any non-administrative user to perform administrative tasks like installation, without actually logging in as root, but with root privileges.
However, there can be certain crucial administrative tasks which are not allowed with the
sudo command and can only be performed when root user is logged in. There are ways to set or reset the root password in such scenarios. Note that, this should be used only in such cases where the command
sudo is incompetent, as logging in as root user possesses a security risk for your computer.
Set/Reset Root Password
This step requires that you are logged in as a user with
sudo privileges and the command
su is allowed as part of
Run the following to login as root. Enter your password when prompted.
As seen above, the prompt has now changed to root. Thus we are able to login to root using our own password.
Now, to change the root password, simply use the command
This will set the root password when used for first time, or change it to the new password when used afterwards.
Time to check if the new password works. Press
Ctrl + D to exit root prompt. Then type command
su to login as root, and enter the new root password which we just set.
In this way, we have successfully modified the root password and able to log in as root.
However, as said before, this requires your own user to have sudo access. But what if you don’t have sudo access but still need to change the root password in case of an emergency? Is there a way to log in as root in such a case? Let’s find out.
Reset Root Password from Grub
There is a way to change the password of root or of any other user for that matter while booting into Ubuntu. It needs a little bit of tweaking the boot process.
First, restart your computer. If the GRUB menu doesn’t automatically appear for you every time while booting, hold the
Shift key while booting. This will forcefully show the GRUB menu.
Next, mark the line
Ubuntu from the menu and press
e to edit the boot configuration.
We need to do the modification on the line starting with
linux, which is the second last line in the configuration. Replace the last part
quiet splash with
Basically the change we are doing here is to login to a shell (
init=/bin/bash) instead of GUI (
quiet splash) with read and write (
F10 to boot with this configuration. Note that this changed configuration is used only for that boot and is reset on the next boot.
As you can see, we are logged in as the root user on the shell prompt.
Now, as done previously, we can run the command
passwd here and reset the root password.
The root password has been changed. Now reboot the system normally and login as root with the new password.
You can now perform the required administrative tasks.
We saw two ways of changing the root password in Ubuntu 20.04. Note that wherever possible,
sudo command must be used to perform administrative tasks. Logging in as
su should be prevented as much as possible, as it can compromise the security of the system, especially if it is connected to a network.