Reset Forgotten Root Password in Ubuntu

You had set up root password in Ubuntu but cannot remember it now? Here's how to reset forgotten root password in Ubuntu and hopefully in other Debian-based distros.
Warp Terminal

It's only human to forget passwords, especially if you are not using it frequently.

It happens with Ubuntu, Linux, or any other operating system you use. If you don't use it frequently, you are likely to forget the password.

I have written about resetting forgotten Ubuntu passwords in the past. It works flawlessly unless you have a root password set.

In this tutorial, I'll show you how to set a new root password if you forget the original one.

Resetting the forgotten root password

βœ‹
This scenario only works when you have root password set up (do not confuse it with the default admin account with sudo access) and you have physical access to the system.

First thing first, I am talking about the case where you have explicitly set a root password.

Let me recall things around the root user in Ubuntu.

When you install Ubuntu, you create a user account. This user account has admin access to install and remove software and do all the other administrative tasks with elevated access thanks to the sudo mechanism.

By default, the root account doesn't have a password. You use sudo with your main/admin account to do things as root. However, some people explicitly set a root password.

And this creates a problem when you try to reset forgotten password using the recovery shell as described in this tutorial. You'll see this error:

Give root password for maintenance

Let me show you how to bypass this error and reset the root password.

Step 1: Go to the recovery mode from Grub screen

When you power on the system, it shows up the grub screen that gives you different options to enter Ubuntu, recovery mode or access UEFI settings.

In here, you use the arrow key to select the Advanced options for Ubuntu:

Access recovery mode for Ubuntu
πŸ’‘
If you don't see the grub screen, press and hold the Shift key as your system boots.

On the next screen, you should see the available kernel options with their respective recovery mode. You can choose the first entry that has recovery mode in it:

Accessing recovery mode in Ubuntu

Step 2: Use dpkg package repair option

The recovery mode gives you various choices. What you need to do here is to go to dpkg Repair broken packages option.

Go to dpkg repair broken packages option

Press tab key to go to OK and then press enter to confirm your choice.

Press Yes when you see this next screen:

Go with remount in read write modew which is essential for restting root password

⚠️ Important step now

It will update the package cache and ask you if you want to upgrade. You have to enter d here for details.

Access root shell with dpkg package update in ubuntu recovery mode
Enter d for details

While it gives you package details, you get access to write something on the screen here. You have to write:

!/bin/bash
Accessing root shell in Ubuntu
Access root shell in Ubuntu

Press enter and you'll be in the root shell. That's a good thing πŸ˜„

Step 3: Reset root password from the root shell

Now, you are using the shell as root user. You don't know the password, so the next step is to use the passwd command and reset its password:

passwd

You'll be asked to enter the password and then repeat the same password.

πŸ“‹
Nothing is displayed on the screen when you type the password. That's normal. Just type the password and press enter.
Reset forgotten root password in Ubuntu

If you see the 'you ', you have fulfilled your mission.

Now to exit this screen, enter the reboot command:

reboot

Conclusion

And that's it. You have successfully used local privilege escalation to reset the forgotten root password in Ubuntu. Enjoy πŸ˜„

Sorry for the poor screenshots. I took it from an actual bare metal system while testing this scenario. As long as you can follow the steps, it should be fine, right?

About the author
Abhishek Prakash

Abhishek Prakash

Created It's FOSS 11 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries πŸ•΅οΈβ€β™‚οΈ

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

It's FOSS

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.