Reset Root Password on Ubuntu 20.04 with Easy Steps
In this guide, you will learn How To Reset Root Password on Ubuntu 20.04. In Linux, root privileges (or root access) refer to a user account that has full access to all files, applications, and system functions. This level of control is necessary for administrative tasks, system maintenance, and software installation. However, losing the root password can lock you out of these essential functions.
However, what if the superuser (or root user) loses his/her password? They will have to recover the lost password before booting into the login screen. This allows any malicious user with physical access to your Linux host to gain complete ownership. This article on the Orcacore website takes a look at how to recover a lost root password on Ubuntu 20.04. Regaining access is crucial, and knowing how to Reset Root Password on Ubuntu 20.04 is an essential skill for any Linux system administrator.
In this guide, we will show you how to reset the Lost Root Password from the Grub Menu on Ubuntu 20.04. Follow the steps below to complete this guide.
First, you need to restart your system, and while doing that, press and hold the Shift key on your Keyboard. This will drop you into the Grub menu of Ubuntu 20.04.
Next, you need to press the ‘e’ key on your keyboard. This will let you edit the Grub’s boot prompt. Don’t touch or delete anything here. Once you have the editor, move to the next step.
At this point, use your arrow key and move to the end of the line starting with “Linux”. There is at the end of this line type rw init=/bin/bash
.
rw init=/bin/bash

After adding the syntax, boot your system with this configuration. To do this, you can use Ctrl+X or F10.
2. Ubuntu Root Shell Access Without Password
At this point, without providing any password, you will have Ubuntu’s shell with root access. First, let’s check whether your user has read and write access to the file system where the OS has been installed.
To do this, run the following command:
mount | grep -w /
If you see (rw,realtime)
in your output, it means you have real-time read and write access to the file system.
3. Change Root Password on Ubuntu 20.04
Now you can simply change your root password with the following command:
passwd
The system will prompt you to add a new password twice.
To change the password of a user other than root, we have to mention the username of the same. The syntax is like the following command:
passwd username
When you are done resetting your Linux password, restart your system to log in with the changed password. For rebooting, run the command below:
exec /sbin/init
After that, hit the Enter key.
From here, you can log in and access your system with the newly set root password. This method allows you to Reset Root Password on Ubuntu 20.04 when you’ve lost access.
Conclusion
At this point, you have learned to Reset Root Password on Ubuntu 20.04. Resetting the root password on Ubuntu 20.04 allows you to regain access to your system if it’s lost. It involves booting into recovery mode, accessing the root shell, and setting a new password using the passwd
command.
Hope you enjoy it. Please subscribe to us on Facebook, Instagram, and YouTube.
You may also like these articles:
Install and Use Podman on Ubuntu 20.04
Install and Configure Django on Ubuntu 20.04
How To Install and Use Cockpit on Ubuntu 20.04
Install and Configure XAMPP on Ubuntu 20.04
FAQs
Will resetting the root password affect my data?
No, resetting the root password doesn’t affect your data, files, or system settings. It only changes the authentication credentials.
How do I boot into Recovery Mode?
Restart your system, hold the Shift key (or Esc on some systems) to access the GRUB menu, then select Advanced options and choose Recovery Mode.
Can I reset the password without booting into Recovery Mode?
No, without recovery mode or a live CD/USB, resetting the password directly from the login screen is not possible.
Alternative Solutions for Resetting the Root Password
While the Grub method described above is a common approach, there are alternative methods to Reset Root Password on Ubuntu 20.04. Here are two additional ways to accomplish this:
1. Using a Live CD/USB
This method involves booting your Ubuntu 20.04 system from a live CD or USB drive. A live environment provides access to the system’s files without requiring the root password.
Steps:
-
Boot from Live Media: Insert the Ubuntu 20.04 live CD/USB into your computer and restart. Ensure your BIOS settings are configured to boot from the removable media.
-
Open a Terminal: Once the live environment has loaded, open a terminal window.
-
Mount the Root Partition: Identify the root partition of your Ubuntu installation. You can use the
lsblk
command to list the available block devices and their partitions. Look for a partition with a size that corresponds to your Ubuntu installation. For example, it might be/dev/sda1
.lsblk
-
Mount the Partition: Mount the root partition to a directory (e.g.,
/mnt
).sudo mount /dev/sda1 /mnt
Replace
/dev/sda1
with the actual device name of your root partition. If you have a separate/boot
partition, you’ll need to mount that as well:sudo mount /dev/sda2 /mnt/boot
Replace
/dev/sda2
with the actual device name of your boot partition. -
Chroot into the Mounted Partition: Use the
chroot
command to change the root directory to the mounted partition. This allows you to run commands as if you were operating directly within your Ubuntu installation. Before doing this, you should mount the virtual file systems.sudo mount --bind /dev /mnt/dev sudo mount --bind /dev/pts /mnt/dev/pts sudo mount --bind /proc /mnt/proc sudo mount --bind /sys /mnt/sys sudo chroot /mnt
-
Change the Root Password: Now that you are in a chroot environment, you can change the root password using the
passwd
command.passwd
Enter the new password when prompted.
-
Exit Chroot and Unmount: Exit the chroot environment and unmount the partitions.
exit sudo umount /mnt/sys sudo umount /mnt/proc sudo umount /mnt/dev/pts sudo umount /mnt/dev sudo umount /mnt/boot #if you mounted it sudo umount /mnt
-
Reboot: Restart your computer and boot from the hard drive. You should now be able to log in as root with the new password.
This method is advantageous because it doesn’t rely on modifying the Grub configuration. It also works if Grub is damaged or inaccessible.
2. Using Systemd’s Emergency Mode
Systemd’s emergency mode provides a minimal environment for system recovery, and it can be used to Reset Root Password on Ubuntu 20.04. This method is particularly useful if you’re unable to access the Grub menu or if the standard recovery mode is failing.
Steps:
-
Interrupt Boot Process: During the boot process, quickly press
Ctrl+Alt+Delete
repeatedly. This will trigger a system reboot, potentially leading to the emergency mode prompt. The timing is crucial; you may need to experiment with when to press the keys. Another approach is to edit the kernel parameters like with the GRUB method, but instead addsystemd.unit=emergency.target
to the end of thelinux
line. -
Access Emergency Mode: After a few attempts, the system should drop you into the emergency mode shell. You might be prompted for the root password, but since you don’t know it, try pressing
Enter
. If that doesn’t work, you might need to try another method. If it works, you will have a root shell. -
Remount Root Filesystem in Read-Write Mode: By default, the root filesystem is mounted as read-only in emergency mode. Remount it in read-write mode to make changes.
mount -o remount,rw /
-
Change the Root Password: Now you can change the root password using the
passwd
command.passwd
Enter the new password when prompted.
-
Reboot: Reboot the system to apply the changes.
reboot
Alternatively, you can try exiting the emergency mode and continuing the boot process, but rebooting is generally safer.
This method bypasses the normal boot process and allows you to directly interact with the system in a recovery environment. This can be valuable in situations where the standard recovery tools are not functioning correctly.
These alternative methods offer flexibility when the Grub method isn’t viable. Remember to exercise caution when working with system-level configurations and always back up your data before making significant changes. Choosing the right method depends on your specific situation and comfort level with Linux system administration. With these techniques, you can effectively Reset Root Password on Ubuntu 20.04 and regain access to your system.