Ubuntu is a Linux distribution based on Debian and open software. Ubuntu runs on a computer alone or in virtual machines and is very popular for cloud computing. There is a superuser called a root for any Linux, including Ubuntu. The root user can do anything over everything and has all the privileges of the system. 

Losing a root password is one of the technical issues that we all suffer from throughout the years. Are you the one who has lost the Ubuntu root password and is worried about retrieving the same? Well! Don't worry! I have come up with an easy guide on resetting the Ubuntu root password.

The good thing is that you don't need to reinstall the whole operating system due to a forgotten password. I have come up with password restoration techniques for single or dual boot VMware to restore Ubuntu passwords. You will regain login credentials effortlessly using them. 

Ubuntu Password Reset from Recovery Mode

In Ubuntu, the system's root password is written inside the root directory of the Linux file system. And it is important to have a root password; else, you cannot log into the system. No administrative tasks can be assigned without a root password.

Resetting your forgotten root password is not unethical while using Ubuntu; you can easily reset the root password for Ubuntu without knowing the current password. Here is the simple process that is to be followed to reset the password in Ubuntu: 

Booting into Ubuntu Recovery Mode

Turn the computer on and get on the grub menu. Press the escape key or hold the shift key down for some time until it opens. While working on a virtual machine or virtual box, you need to press the shift key when the oracle or the virtual machine logo appears. When the grub menu appears on the screen of your virtual machine, the following lines will be displayed on your screen. 

Ubuntu

*Advanced options for Ubuntu

Memory test (memtest86+)

Memory test (memtest86+, serial console 115200)

Advanced

Go to advanced options for Ubuntu. The following lines will be displayed on your screen, and an option will also be displayed saying recovery mode. 

Ubuntu, with Linux 5.4.0-40-generic

*Ubuntu, with Linux 5.4.0-40-generic (recovery mode)

Ubuntu, with Linux 5.4.0-26-generic

Ubuntu, with Linux 5.4.0-26-generic (recovery mode)

Root shell prompt

Select the option Ubuntu, with Linux 5.4.0- 40- generic (recovery mode) to go to recovery mode. On clicking on this, you will see a black screen that flashes multiple lines of data. Wait for some time here until numerous recovery mode options are made available. 

Recovery menu (filesystem state: read-only)

Resume normal boot

clean Try to make free space

dpkg Repair broken packages

fsck Check all file systems

grub Update grub bootloader

network Enable networking

root Drop to the root shell prompt

system- summary System summary 

Select the option that says "Root – Drop to Root Shell Prompt" from the list of options. Click on the enter button. Now, root Drop to the root shell prompt. 

On clicking enter, you will notice that you will see the option to enter commands at the bottom. This is the prompt for your shell, and here you need to restore the forgotten password.

Remount Root Filesystem with Write Access

By default, there are read-only privileges in the root partition. But you need to have both the read and write option access too. Type the following command to have the write access:

ubuntu@ubuntu:~$ mount -rw -o remount /

Reset the username and password:

Now you have root access, list the available users using the command:

ubuntu@ubuntu:~$ ls /home

You can also see the list of available users by displaying the contents of the/etc/passwd file with the help of the following command:

ubuntu@ubuntu:~$ cat /etc/passwd

From the list of usernames available, select the one you would like to rest the password. After selecting the username, type the following command to reset the password for the chosen username.

ubuntu@ubuntu:~$ passwd <user>

Enter new UNIX password:

It will ask for the new password. Retype the new password once again to confirm it.

ubuntu@ubuntu:~$ Retype new UNIX password:

You have now successfully restored the password. Now enter the exit command to exit the root shell.

ubuntu@ubuntu:~$ exit

On entering the exit command, you will be reverted to the Recover Boot Menu. You have now chosen the standard boot option on the screen. Suppose there will be an alert about compatibility with the graphics mode, no need to worry. Rebooting will sort out all these compatibility issues. All you need to do is to log in with the password that you had set. 

If any error is encountered:

You may encounter with authentication token manipulation error while entering a new password, and your screen will display the following error:

passwd username
Enter new UNIX password:
Retype new UNIX password:
passwd: Authentication token manipulation error.
passwd: passwd unchanged.

The cause for this error is that root is still mounted with Read-only access. To overcome this, type the following command that will remount the file system and remount the access.

mount -rw -o remount /

You now need to change the password once again. It will now start to work without showing any errors. 

An Alternative Method for Resetting a Password

If you cannot change your password via root shell due to some reason, here is a quick read for you. You can also change the password by following these steps:

Reboot your computer. Bring on the grub screen by long-pressing the shift key. To edit the grub panel, press the control key + E. You will be displayed with some of the following lines.

insmod gzio
insmod part_msdos
insmod ext2
set root= 'hd0, msdos1'
if [ x$feature_platform_search_hint =xy ] ; then
search --no-floppy --fs-uuid --set=root --hint --bios=hd0, ms\
dos1 --hint --efi=hd0, msdos1 --hint -baremetal=ahci0, msdos1 c26c296-7\
741 -4264 -bb53- 1af8167bbaae
else
search -no-floppy -fs-uuid -set=root c26c296f-7741-4264\
-bb53- 1af8167bbaae
fi
linux /bootvmlinuz-3.5.0-17-genric root=UUID=c26c29\
6f-7741-4264-bb533-1af8167bbaae ro quiet splash $vt_handoff
initrd /boot/initrd.img-3.5.0-17-genric

From the given set of lines, find any line starting with Linux using up and down arrow keys and change access to read-write from read-only by replacing ro recovery nomodeset to rw init=/bin/bash

insmod gzio
insmod part_msdos
insmod ext2
set root= 'hd0, msdos1'
if [ x$feature_platform_search_hint =xy ] ; then
search --no-floppy --fs-uuid --set=root --hint --bios=hd0, ms\
dos1 --hint --efi=hd0, msdos1 --hint -baremetal=ahci0, msdos1 c26c296-7\
741 -4264 -bb53- 1af8167bbaae
else
search -no-floppy -fs-uuid -set=root c26c296f-7741-4264\
-bb53- 1af8167bbaae
fi
linux /bootvmlinuz-3.5.0-17-genric root=UUID=c26c29\
6f-7741-4264-bb533-1af8167bbaae rw init=/bin/bash
initrd /boot/initrd.img-3.5.0-17-genric

To save changes and boot, press the control key and X. With this command, you are now booting with both read and write access rights into a Linux kernel. Here you can use a bash shell instead of a graphical user interface. In other words, you will now have a passwordless root shell booted into your system.

Type the username into the passwd command. If your username is unknown to you, search with the following command.

ls /home' or 'cat /etc/passwd | grep -i bash

You can now reset the password and then exit the terminal. After all, this is done, reboot your system with the following command, and you are all good to go.

ubuntu@ubuntu:~$ reboot
ubuntu@ubuntu:~$ shutdown -r now

Security Concerns

Ubuntu's root account gets locked as soon it does not have a root password by default. A user account that you set up before installing Ubuntu in your system is included as an administrator. The administrator gets sudo privileges soon after installing Ubuntu on your system. You can write sudo for any command that may require Ubuntu root privileges. 

However, in any situation, it does not apply that it is a root. Though the absence of a root password is an intended feature of Ubuntu, the boot menu for "Ubuntu Advanced Options" allows you to perform many functions related to root right, starting from the root prompt shell. This is the main reason that you can reset the Ubuntu password from this method.

You may wonder if it is that easy to reset and restore a password, there must be a security risk involved. You may think that anyone can break into your system from a different location through the internet and would be a security threat to your account. But it is not the case with Ubuntu. 

However, getting physical access to your system may be a problem. To save your system from this physical attack, you need to disable it by encrypting your Hard Drive via LUKS encryption. The encryption must be done while installing Ubuntu.

Conclusion

Ubuntu is an adaptable version of Linux. If you have not used Ubuntu for a long time, it is obvious to forget the password. You may think of deleting the operating system from your computer and reinstalling Ubuntu. But why would you do that when you can reset the password? 

You don't need to worry; I have covered all the steps in the above guide and will tell you how to reset your password on Ubuntu. All you are required to have some patience and confidence. You need to run a couple of commands that will reset your Ubuntu password within minutes.

People also read: