Reset Forgotten Root Password in Ubuntu
![Reset Forgotten Root Password in Ubuntu](https://itsfoss.com/content/images/2024/06/reset-forgotten-root-password-in-ubuntu.png)
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
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:
![Reset Forgotten Root Password in Ubuntu](https://itsfoss.com/content/images/2024/06/access-advanced-options-for-ubuntu-from-grub-screen.png)
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:
![Reset Forgotten Root Password in Ubuntu](https://itsfoss.com/content/images/2024/06/accessing-recovery-mode-ubuntu.webp)
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.
![Reset Forgotten Root Password in Ubuntu](https://itsfoss.com/content/images/2024/06/ubuntu-recovery-dpkg-broken-package.webp)
Press tab key to go to OK and then press enter to confirm your choice.
Press Yes when you see this next screen:
![Reset Forgotten Root Password in Ubuntu](https://itsfoss.com/content/images/2024/06/using-dpkg-package-repair-option.webp)
⚠️ 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.
![Reset Forgotten Root Password in Ubuntu](https://itsfoss.com/content/images/2024/06/get-dpkg-package-details.webp)
While it gives you package details, you get access to write something on the screen here. You have to write:
!/bin/bash
![Reset Forgotten Root Password in Ubuntu](https://itsfoss.com/content/images/2024/06/access-root-shell-ubuntu.jpg)
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.
![Reset Forgotten Root Password in Ubuntu](https://itsfoss.com/content/images/2024/06/reset-ubuntu-root-password-in-recovery.webp)
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?