How to Reset a Forgotten Root Password in Linux

Forgot your Linux root password? No worries! Our guide provides easy-to-follow instructions to reset and change it safely.

Have you ever found yourself locked out of your Linux system, staring blankly at the login screen because you can’t recall your root password? It’s a common scenario that can be frustrating, especially when you need urgent access to your system.

But fear not because in the world of Linux, forgetting your root password is not the end of the road. Our simple but proven effective guide is here to rescue you from this predicament.

Resetting Your Linux Root Password

To reset your Linux root password, you’ll need physical access to the machine or the console if you’re working on a virtual machine, as restarting the system is part of the procedure.

Change GRUB Boot Parameters

Reboot your Linux system, and when the GRUB boot menu appears, highlight the line with your distribution name, then press the “e” key to enter edit boot parameters mode.

Highlight the row and press the "e" key.
Highlight the row and press the “e” key.

Find the line starting with “linux” and make sure it contains “rw” and not “ro“. If not, change it. Then go and append “init=/bin/bash” to the end of the line, as the final version should be similar to the one shown below.

Changing boot parameters in Linux.
Changing boot parameters in Linux.

So, what did we do? Let me explain. In the context of GRUB boot parameters, “ro” and “rw” are options that specify how the filesystem should be mounted during the boot process:

  • ro“: This stands for “read-only”. When it’s used, the filesystem is mounted in read-only mode. It’s often a default setting for many Linux systems during the initial boot process to perform filesystem checks during the startup. Then, after the initial boot checks are complete, the system remounts the filesystem with “rw” to allow normal operations.
  • rw“: This stands for “read-write.” When this parameter is set, the filesystem is mounted in read-write mode. This means the system can both read from and write to the filesystem. It’s also the option we need because to reset the root password, we must set a new one. This involves writing to certain files on the file system, hence the need for “rw “.

Ok, but what about “init=/bin/bash“? In short, this parameter tells the system to start with the Bash shell as the initial process instead of the usual init system. As a result, this effectively gives you immediate access to a root shell without needing to log in, where we will be able to change the password for the root account.

Now that everything is in place, press “Ctrl+X” to start the boot process.

Reset the Root Password

The system will boot in single-user mode, and you will end up with a Bash shell with a logged root account.

Remount the file system with write access.
Remount the file system with write access.

To update the password for the root user, we simply need to execute the passwd command and then establish a new one.

passwd
Resetting the root password on Linux.
Resetting the root password on Linux.

To enhance your proficiency in using the passwd command on Linux, our comprehensive guide “How To Use passwd Command on Linux with Examples” will significantly benefit you.

And that’s it! You’ve successfully reset the root user password on your Linux system. Now, all you left to do is reboot your system, and you’ll be all set to regain access. Great work!

reboot -f

Conclusion

Forgetting your Linux root password is not the end of the world. With our straightforward guide, you’ll learn how to reset and change it safely and efficiently. We hope this process was simple to follow and helped alleviate any stress associated with this common issue.

Thanks for your time! As always, your feedback and comments are most welcome.

Bobby Borisov

Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.

Think You're an Ubuntu Expert? Let's Find Out!

Put your knowledge to the test in our lightning-fast Ubuntu quiz!
Ten questions to challenge yourself to see if you're a Linux legend or just a penguin in the making.

1 / 10

Ubuntu is an ancient African word that means:

2 / 10

Who is the Ubuntu's founder?

3 / 10

What year was the first official Ubuntu release?

4 / 10

What does the Ubuntu logo symbolize?

5 / 10

What package format does Ubuntu use for installing software?

6 / 10

When are Ubuntu's LTS versions released?

7 / 10

What is Unity?

8 / 10

What are Ubuntu versions named after?

9 / 10

What's Ubuntu Core?

10 / 10

Which Ubuntu version is Snap introduced?

The average score is 68%