Jan 21, 2026 by Zacharia Mansouri | 322 views
https://cylab.be/blog/477/how-to-reset-a-forgotten-root-password-on-linux-distros
Losing track of a root password can feel genuinely frustrating, whether you’re reviving an old machine or diving back into a forgotten VM. The good news is that Linux’s flexible bootloaders give you an interesting workaround: with physical or console access, you can interrupt the boot sequence, drop straight into a shell, and reclaim the system long before it ever asks for credentials. It’s a clean and fast way to get back in control without reinstalling or starting from scratch.
If you don’t use Full-Disk Encryption (LUKS) nor a Locked Bootloader (GRUB Password), just follow the guide hereunder and you’ll recover that machine in no time!
Ensure the system is completely powered off.
Start the device again. When you see the GRUB boot menu, press the e key on the keyboard before the system starts booting.
Troubleshooting: VM boots too quickly to see GRUB?
If you are using a Virtual Machine (VirtualBox, VMware, KVM) or a fast-booting UEFI system, the window often disappear in the blink of an eye.
- IOS / Legacy Boot: Click inside the window immediately and hold the
Left Shiftkey.- UEFI Boot: Click inside the window and rapidly tap the
Esckey (do not hold it).
In the GRUB boot options, use the arrow keys to scroll down and locate the line that begins with linux (or linux16 / linuxefi).
ro quiet).ro quiet or ro (if there is no quiet).ro (read-only) to rw (read-write).init=/bin/bash to the end of the line.The line should look like this:
linux ... rw init=/bin/bash
Press Ctrl+x or F10 to boot.
You will see a root command prompt (usually indicated by #).
Set the password for the root user (or any other user with root access):
passwd root
(Enter the new password twice when prompted)
Troubleshooting: Filesystem is not writable.
If the filesystem is not writable:
- Remount it manually with the command:
mount -no remount,rw /- Then try again the
passwd <user>command from above.
Once the password is changed, reboot the system.
reboot -f
Alternatively, if that command hangs:
exec /sbin/init
Congratulations, you successfully updated a password through the GRUB!
The method above relies on having unrestricted physical access to the machine. Here are three common security configurations that will prevent this method from working.
If the system uses Full-Disk Encryption (FDE), the hard drive is locked before the operating system even loads.
init=/bin/bash command is stored inside the encrypted partition. You cannot access /bin/bash or /etc/shadow (where passwords are stored) without first unlocking the drive.Administrators can protect the GRUB menu itself with a password in order to prevent unauthorized edits.
e to edit the boot parameters, GRUB will prompt you for a username and password. Without these credentials, you cannot add init=/bin/bash.grub.cfg file manually.Regaining root access through GRUB is a powerful skill that can turn a locked‑out system from a crisis into a quick fix, sparing you from reinstallations or data loss. At the same time, the very simplicity of this recovery method shows an important facet about security: anyone with physical access to a machine can often gain full control. Consider this not not only as a rescue technique but also as a reminder to strengthen your defenses, using tools like full‑disk encryption to ensure that you alone hold the keys to your data.
This blog post is licensed under
CC BY-SA 4.0