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.
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.
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.
To update the password for the root user, we simply need to execute the passwd
command and then establish a new one.
passwd
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.
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.
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.