Senin, 17 Juni 2024

Reset Forgotten Root Password in Ubuntu

Reset Forgotten Root Password in Ubuntu

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:

Reset Forgotten Root Password in 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:

Reset Forgotten Root Password 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.

Reset Forgotten Root Password in Ubuntu

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

⚠️ 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
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
Reset Forgotten Root Password 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?



from It's FOSS https://ift.tt/T9RuEyS
via IFTTT

Tidak ada komentar:

Posting Komentar