In Linux, there are two types of users: the root user, who is the most important and has the highest privileges, and normal users, some of whom have sudo access that grants them limited root user powers.

When installing a Linux distribution like Ubuntu, the Ubuntu Installer (Ubiquity) provides an option to set a password for the root user and create a separate user with sudo access.

Users continue to use their normal accounts with sudo access, and as a result, they often forget the password they set for the root account, locking them out of their regular user accounts. And someone with only the root account forgetting their password could be worse.

So, in this article, I'll show you how to reset the root user password on Ubuntu 24.04, Ubuntu 22.04, and Ubuntu 20.04 using two methods.

Resetting the Forgotten Root Password in Ubuntu (via 2 Method)

There are two ways to reset a forgotten root password in Ubuntu that you can apply based on the situation.

  1. Resetting the forgotten root password with a sudo user account.
  2. Resetting the forgotten root password directly from the GRUB bootloader.

The first method only works on systems with at least one sudo user account, while the second method would work in any circumstance. So, let's begin with…

Method 1: Resetting the Forgotten Root Password with Sudo User Account

To reset the root user password with a sudo user account, simply boot your system, log in to your sudo user account, open your terminal, and execute the following command, which will prompt for a sudo user password.

$ sudo passwd root
granting sudo privilege

After that, it will prompt you to enter a new root user password twice for verification.

resseting the forgetten root password on ubuntu using sudo user

Once you're done, your root user password will be changed to the entered password, and you can now switch to the root user account from your desktop environment or by using the following command:

$ su
entering to root user account

Well, you now have your root user password reset, but what if you have a system without any sudo user accounts, or if they exist but you don't have access to them? Relax, the next method will work in all these situations.

Method 2: Resetting the Forgotten Root Password Directly from the GRUB Bootloader

This method is quite useful for systems that don't have a user account with sudo privileges, or if you need to investigate a system, it allows you to easily bypass the root user password.

So, begin by booting the system, and once the GRUB screen appears, use the arrow keys to select "Advanced options for Ubuntu".

ubuntu grub screen

On the next screen, you'll see a list of available kernel options along with their respective recovery modes. Opt for the first entry that includes recovery mode.

entering in recovery mode

Now, you'll interact with the recovery menu, which offers various options. The one you need to select is "dpkg: Repair broken packages". Use the arrow keys to navigate, press Tab to go to "Ok", and then press Enter to confirm your choice.

grub recovery mode

Choose "Yes" to continue when the next screen appears.

mounting filesystem for recovery mode

It will update the package cache and ask you if you want to upgrade them. Simply ignore the upgrade and enter d for details.

enter d for details

The package details will be printed, and you will also be able to write something on the screen. Thus, enter the following command to access the root shell:

accessing the root shell in ubuntu

Since you have root access to the shell, you can now use the following command to reset the root user account password:

# passwd

You will be asked to enter the password twice for verification, and the entered password will not be displayed on the screen, which is standard procedure.

resseting root user account password in ubuntu

Once you are done, you can reboot the system using the following command and access the root user account with the new password.

# reboot

Wrap Up

Today, you've learned two different ways to reset a root user password on Ubuntu: one that is straightforward but requires a sudo user account, and another that works in any situation.

This step was performed on an Ubuntu system, but it can also work for other Linux distributions such as Debian, Linux Mint, or Pop!_OS.