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%

6 Comments

  1. Thanks for this refresher.

    But now that I’m using PopOS which uses systemd-boot this BRUB-based method cannot be used.

    Consider adding to this article how to perform this feat for systemd-boot machines.

  2. Thanks for the clear explanation of how to do that.

    I was hoping that would solve my problem but it did not. My Ubuntu 22.04.3 LTS operating system recognizes my root password when booting up but not for system software updates or when attempting sudo commands. It used to work but mysteriously, no longer. Any suggestions on why that would be?

    • Hi Tim,

      In fact, using the sudo command in Ubuntu doesn’t involve the root user’s password at all. I believe that in Ubuntu 22.04, the root account is typically disabled by default. So, in your situation, the only requirement is that your user must be a member of the ‘sudo’ group.

      Another way you can approach this is to enable the root user on your Ubuntu 22.04 system. To do so, first execute:
      sudo -s
      Then, set a password for the root user:
      passwd root

      Best,
      Bobby

      • Thanks, Bobby.
        Here’s what I did…
        tim@tim-Precision-T1700:~$ sudo -s
        [sudo] password for tim:
        Sorry, try again.
        [sudo] password for tim:
        What am I missing?

        • Hey Tim,

          Can you execute other commands prefixed with sudo? By running ‘id‘, is your user a ‘sudo’ group member?

          • No, I cannot do ‘sudo’ commands. I used to be able to but, inexplicably, Previously, the same password I use for logging in upon startup would work for the ‘sudo’ commands and for certain system updates, but no longer.
            Don’t know if my user is a ‘sudo’ group member, but here is the result of the command, “id”…
            tim@tim-Precision-T1700:~$ id
            uid=1000(tim) gid=1000(tim)
            groups=1000(tim),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),120(lpadmin),132(lxd),133(sambashare)
            I’m not sure how to interpret it, though.

Leave a Reply

Your email address will not be published. Required fields are marked *