How to Reset Root Password in Ubuntu 18.04

The Challenge of Resetting Root Password

Video Tutorial:


As a Linux user, it is important to have access to the root account to manage the system effectively. However, sometimes you might forget the root password, and lose access to important system settings and files. The good news is that there are several ways to reset the root password in Ubuntu 18.04. In this post, we provide you with 3 methods to reset the root password in Ubuntu 18.04.

Things You Should Prepare for

Before we dive into the methods of resetting the root password, there are a few things that you should prepare for:

1. A Ubuntu 18.04 live CD or USB flash drive.
2. Basic knowledge of using command-line tools in Ubuntu.
3. An external storage device to back up your important data in case something goes wrong during the process.

Method 1: Using the Recovery Mode (Boot Menu)

The first method involves using the Recovery Mode (Boot Menu) to reset the root password in Ubuntu 18.04.

Step 1: First, insert the Ubuntu 18.04 live CD or USB flash drive and restart your system to boot from it.

Step 2: Select the "Try Ubuntu" option in the boot menu to use Ubuntu in live mode.

Step 3: After Ubuntu starts, open the terminal window by pressing Ctrl+Alt+T.

Step 4: In the terminal window, run the following command to mount the root partition:

"`
sudo mount /dev/sda1 /mnt
"`

Note: Replace sda1 with the partition that contains the root file system on your system.

Step 5: Next, run the following command to change the root directory to the mounted partition:

"`
sudo chroot /mnt
"`

Step 6: Now, you can reset the root password by running the following command:

"`
passwd root
"`

Step 7: Follow the on-screen instructions to create a new root password.

Step 8: Quit the terminal window by running the following command:

"`
exit
"`

Step 9: Finally, restart your system by running the following command:

"`
sudo reboot
"`

Pros:
• This method is quite simple and straightforward.
• It does not require additional software or tools to reset the root password.

Cons:
• It may not work if the root filesystem is encrypted.
• It is a bit time-consuming, as it requires booting from a live CD or USB.

Method 2: Using the Single-User Mode

The second method involves using the Single-User Mode to reset the root password in Ubuntu 18.04.

Step 1: Start your system and press the Shift key to display the GRUB boot menu.

Step 2: Select the Ubuntu 18.04 option and press e to edit the boot parameters.

Step 3: Navigate to the line that starts with "linux" and add "init=/bin/bash" at the end of the line, as shown below:

"`
linux /boot/vmlinuz-4.15.0-33-generic root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ro quiet splash init=/bin/bash
"`

Note: Replace the UUID with the UUID of your system’s root partition.

Step 4: Press Ctrl+X to start Ubuntu in Single-User Mode.

Step 5: Once Ubuntu starts, you should see the root prompt (#). Run the following command to remount the root partition with write permissions:

"`
mount -o remount,rw /
"`

Step 6: Now, you can reset the root password by running the following command:

"`
passwd root
"`

Step 7: Follow the on-screen instructions to create a new root password.

Step 8: Finally, reboot your system by running the following command:

"`
reboot -f
"`

Pros:
• This method is quicker than the first method as it does not require booting from a live CD or USB.
• It can be used even if the root filesystem is encrypted.

Cons:
• You need to be careful when editing the boot parameters as any mistake can cause boot failures.
• It requires basic knowledge of command-line tools in Ubuntu.

Method 3: Using the Advanced Options in GRUB Menu

The third method involves using the Advanced Options in the GRUB menu to reset the root password in Ubuntu 18.04.

Step 1: Start your system and press the Shift key to display the GRUB boot menu.

Step 2: Select the Ubuntu 18.04 option and press e to edit the boot parameters.

Step 3: Navigate to the line that starts with "linux" and add "init=/bin/bash" at the end of the line, as shown below:

"`
linux /boot/vmlinuz-4.15.0-33-generic root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ro quiet splash init=/bin/bash
"`

Note: Replace the UUID with the UUID of your system’s root partition.

Step 4: Press Ctrl+X to start Ubuntu in Single-User Mode.

Step 6: Once Ubuntu starts, you should see the root prompt (#). Run the following command to remount the root partition with write permissions:

"`
mount -o remount,rw /
"`

Step 7: Now, you can reset the root password by running the following command:

"`
passwd root
"`

Step 8: Follow the on-screen instructions to create a new root password.

Step 9: Finally, reboot your system by running the following command:

"`
reboot -f
"`

Pros:
• This method is similar to the second method, but it provides a more convenient way to access Single-User Mode.

Cons:
• It still requires editing boot parameters, which can be tricky for new users.
• It also requires some basic knowledge of using command-line tools in Ubuntu.

Why Can’t I Reset Root Password?

There are several reasons why you might not be able to reset the root password in Ubuntu 18.04. Here are some common reasons and how to fix them:

1. Encrypted root filesystem – in this case, you need to decrypt the root filesystem first before resetting the root password.
2. Forgotten username – if you have forgotten the username as well as the password, you need to boot from a live CD or USB and change the username in the /etc/passwd file.
3. Damaged file system – if the file system is damaged, you might need to back up your important data and reinstall Ubuntu.

Additional Tips

• Always back up your important data before attempting to reset the root password.
• Keep your Ubuntu system updated to prevent security vulnerabilities.
• Use a strong root password to improve security.

5 FAQs about Resetting Root Password in Ubuntu 18.04

Q1. Can I reset the root password without booting from a live CD or USB?
A1. Yes, you can use the Single-User Mode or Advanced Options in the GRUB menu to reset the root password without a live CD or USB.

Q2. What happens if I forget both the username and the password?
A2. You need to boot from a live CD or USB and change the username in the /etc/passwd file.

Q3. Can I reset the root password if the root filesystem is encrypted?
A3. Yes, you can reset the root password, but you need to decrypt the root filesystem first.

Q4. What should I do if I encounter errors during the process?
A4. It is best to seek help from experts or refer to the Ubuntu forums for troubleshooting.

Q5. Is it possible to prevent forgetting the root password?
A5. Yes, you can store the root password in a secure password manager or use a password recovery disk.

In Conclusion

Resetting the root password in Ubuntu 18.04 is not a difficult task if you know the right methods. In this post, we have provided you with 3 methods to reset the root password in Ubuntu 18.04, as well as some additional tips and FAQs to help you along the way. Remember to always back up your important data before attempting to reset the root password, and keep your Ubuntu system updated to prevent security vulnerabilities.