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:
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:
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.
Press tab key to go to OK and then press enter to confirm your choice.
Press Yes when you see this next screen:
âš ï¸ 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.
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/bashAccess 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.
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?
Source: Read More