Categories: Ubuntu

How to Reset Forgotten Root Password in Ubuntu?

In any UNIX or Linux system, the root account is the top in the hierarchy. It holds the utmost power over the system. For any system change, the root has to grant permission. The root user can also override any user’s permission and read or write data. Because the root account holds so much power, it is important to protect it from unwanted access.In the case of Ubuntu, the root account is disabled by default. However, you can still perform system changes. To do so, you need to know the root password. The problem arises when you have forgotten the root password.

Sponsored

Check out how to reset the forgotten root password in Ubuntu.

Reset forgotten root password

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

Method 1: Root shell from boot

When you are booting into Ubuntu, press, and hold Shift. This should open up the GRUB menu. In case there is multi-boot configured, there is probably no need to press the Shift key.


Select “Ubuntu” and press “e”. This will open up the grub parameters to edit.


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


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


Press “Ctrl + X” or F10. This will reboot the system with the tweaks we just made. It will start the system and directly land you on the root shell. It is just a one-time thing, so next time the system boots, it will boot normally into the operating system.

Run the following command to confirm if the root filesystem mounted successfully.

$ mount | grep -w /


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

$ passwd


Once the password is changed, you will see the success message.

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

$ exec /sbin/init

Method 2: Change password from Ubuntu live session

For this method to work, we need to have bootable media made from Ubuntu ISO. Download Ubuntu ISO. In my case, I’m running Ubuntu 20.04.1 LTS.

Sponsored


Make a bootable USB flash drive. Check out how to make 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, fire up a terminal.

We need to identify the root filesystem partition. The following command will list all the partitions in the system. The key point of the output is the last section, where there is a short table of partitions.

$ sudo fdisk -l



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

$ sudo mount /dev/sda5 /mnt


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

$ for d in dev sys run proc; do sudo mount –bind /$d /mnt/$d; done


Now, become the root of the system using chroot.

$ sudo chroot /mnt

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

$ passwd


Once the process is finished, reboot the system.

Final thoughts

As demonstrated, there is no need to fear when you have forgotten the root password in Ubuntu. Here, two methods are demonstrated. Follow the one that you feel comfortable with.

Now, these methods also open up the question of security. In case there is someone else having physical access to the computer. These methods could be used against you. To prevent this, you should configure a password to access the BIOS and boot menu. All modern computers have this feature built-in. However, this is a password that you MUST NOT FORGET.

Happy computing!

Ubuntu Server Admin

Recent Posts

How to Fix VMware’s “Could not open /dev/vmmon” Error on Ubuntu

You’ve recently installed VMware Workstation on your Ubuntu system and encountered the frustrating “Could not…

5 hours ago

How to Fix Ubuntu 404 Errors While Fetching Dependencies

Have you ever found yourself staring at a terminal full of 404 errors while trying…

5 hours ago

How to Fix ‘Please Install All Available Updates’ Error When Upgrading Ubuntu 18.04 to 20.04 LTS

One particularly frustrating error that many users face when trying to upgrade from Ubuntu 18.04 …

5 hours ago

How to fix “Release is not valid yet” Error in Docker Containers

In the world of containerization, time synchronization issues can create unexpected roadblocks when working with…

5 hours ago

How to fix “Externally Managed Environment” Pip Errors on Ubuntu

If you’ve recently upgraded to Ubuntu 23.04 or newer, you might have encountered a frustrating…

5 hours ago

Ubuntu now officially supports NVIDIA Jetson: powering the future of AI at the edge

Canonical announces the General Availability of Ubuntu for the NVIDIA® Jetson Orin™ for edge AI…

12 hours ago