How do I reset a forgotten root password in Ubuntu?

In any UNIX or Linux system, the root account is at the top of the hierarchy. It has the greatest power over the system. The root must grant authorization for every system change. The root user can also override any user’s authority and read or write data. Because the root account has so much power, it’s important to protect it from unwanted access. In the case of Ubuntu, the root account is disabled by default. However, you can still make system changes. To do this, you need to know the root password. The problem occurs when you forget the root password.

Check out how to reset forgotten root password in Ubuntu.

Reset forgotten root password

Although difficult, it is still possible to reset forgotten root password in Ubuntu. There are several methods of doing this. In short, the process is to get access to the root shell and change the password from there.

Method 1: root shell from booting

Hold down the Shift key while booting Ubuntu. This should open the GRUB menu. If multi-boot is configured, the Shift key probably does not need to be pressed.

Select “Ubuntu” and press “e”. This will open the Grub parameters for editing.

Now use the arrow keys and scroll down to the line that begins with “linux / boot / vmlinuz”.

In this line, replace “ro quiet splash $ vt_handoff” with “rw init = / bin / bash”.

Press “Ctrl + X” or F10. This will restart the system with the optimizations you just made. It starts the system and lands directly on the root shell. It’s just a one time thing. The next time the system boots, it will boot into the operating system normally.

Run the following command to confirm that the root file system was mounted successfully.

$ assemble | grep -w /

Now run the passwd command to change the root password.

$ passwd

As soon as the password has been changed, you will see the success message.

The task is over. Run the next command to reboot the system.

$ executive /sbin/inside

Method 2: change the password from the Ubuntu live session

In order for this method to work, we need bootable media from Ubuntu ISO. Download Ubuntu ISO. In my case, I’m using Ubuntu 20.04.1 LTS.

Create a bootable USB flash drive. Check out how to create a bootable USB drive.

Boot into the Ubuntu bootable media. When prompted, select “Try Ubuntu”. This will start the Ubuntu Live session.

Once you are in the live session, start a terminal.

We need to identify the root file system partition. The following command lists all partitions in the system. The crux of the output is the last section, which has a short table of partitions.

$ sudo fdisk -l

From the table we found that the boot partition is / dev / sda5. Now mount it by running this command.

$ sudo assemble /developer/sda5 /mnt

Run the next command to cross mount things from the live install.

$ to the D. in dev sys run proc; to do sudo assemble –tie /$ d /mnt/$ d; did

Now chroot to the root of the system.

$ sudo chroot /mnt

Finally, run the passwd command to change the root password.

$ passwd

Once the process is complete, restart the system.

Final thoughts

As shown, if you have forgotten the root password in Ubuntu, you don’t need to worry. Two methods are demonstrated here. Follow the one you are comfortable with.

These methods now also open up the question of security. In case someone else has physical access to the computer. These methods could be used against you. To prevent this, you should configure a password for access to the BIOS and the boot menu. All modern computers have this built-in feature. However, this is a password you DO NOT HAVE TO FORGET.

Have fun calculating!

Related Posts