Learning Academy

The Cure of Ignorance is to Question. MUHAMMAD (PBUH)

LinuxLinux

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

  1. Shut down your device.
  2. 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

  1. In the GRUB boot options, locate the line that starts with
    1
    linux
    .
  2. Scroll to the end of this line, after ‘ro quiet’, and remove everything after it.
  3. Change ‘ro’ to ‘rw’ (to enable read/write mode).
  4. Append this parameter:
    1
    init=/bin/bash

Step 3: Boot into Single-User Mode

  1. Press Ctrl + X or F10 to boot.
  2. You will see a root shell prompt:
    1
     #

Step 4: Remount the Filesystem in Read/Write Mode

  1. Run the following command to enable write mode:
    1
    mount -o remount,rw /

Step 5: Reset the Root Password

  1. Use the following command to set a new root password:
    1
    passwd root
  2. If resetting a specific user password, replace root with the username (example: passwd <username>) :
    1
    passwd username

Step 6: Reboot the System

  1. Reboot the system using one of the following commands:
    1
    reboot -f
    OR
    1
    exec /sbin/init
  2. 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:
    1
    touch /.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!

Related Articles


Muhammad Shaukat

Content Developer at LearnAcad.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest