How to Reset a Forgotten Root Password in Linux Using GRUB (Step-by-Step Guide)
Introduction
Forgetting the root password in Linux can lock you out of your system, but there’s a way to reset it using GRUB without reinstalling your OS. This step-by-step guide will help you recover a forgotten root password in Linux on distributions like Ubuntu, Debian, CentOS, and Fedora by modifying GRUB bootloader settings.
Steps to Reset Root Password Using GRUB
If you’re using a laptop or desktop, follow these steps to regain access to your system.
Step 1: Access the GRUB Menu
- Shut down your device.
- Turn it back on, and when the GRUB menu appears, press the ‘e’ key before the system boots.
If the GRUB menu is hidden, press Shift (BIOS) or Esc (UEFI) while booting.
Step 2: Modify Boot Parameters
- In the GRUB boot options, locate the line that starts with
.1linux
- Scroll to the end of this line, after ‘ro quiet’, and remove everything after it.
- Change ‘ro’ to ‘rw’ (to enable read/write mode).
- Append this parameter:
1init=/bin/bash
Step 3: Boot into Single-User Mode
- Press Ctrl + X or F10 to boot.
- You will see a root shell prompt:
1#
Step 4: Remount the Filesystem in Read/Write Mode
- Run the following command to enable write mode:
1mount -o remount,rw /
Step 5: Reset the Root Password
- Use the following command to set a new root password:
1passwd root
- If resetting a specific user password, replace root with the username (example: passwd <username>) :
1passwd username
Step 6: Reboot the System
- Reboot the system using one of the following commands:
OR1reboot -f1exec /sbin/init
- The new password should now work, and you can log in as root.
Additional Notes
- This method works on Ubuntu, Debian, CentOS, Fedora, and other Linux distributions using GRUB.
- If using LUKS-encrypted partitions, you will need to unlock them before modifying the password.
- If the system still asks for a password after rebooting, check if SELinux is enabled and relabel files:
1touch /.autorelabel reboot
Frequently Asked Questions (FAQs)
Q1: Can I reset my Linux root password without GRUB?
Yes, but you may need a Live USB to access the system and reset the password using
1 | chroot |
Q2: What if my GRUB menu doesn’t appear?
Try pressing Shift (BIOS) or Esc (UEFI) during boot. If GRUB is still missing, use a Live CD to repair GRUB.
Q3: Is there a way to prevent forgetting my Linux root password?
Consider setting up SSH key-based authentication, password managers, or adding a recovery user with sudo privileges.
Conclusion
Now you know how to reset a forgotten root password in Linux using GRUB. This method ensures that you regain access without losing data. If you found this guide helpful, share it with others or check out our Linux security best practices to prevent future issues!