How to Recover Root Password in Red Hat-based Linux Systems

How to Recover Root Password in Red Hat-based Linux Systems

Introduction

Losing your root password on a Red Hat-based Linux server can be a serious problem. However, the recovery steps are simple if you follow this guide. Therefore, you can easily reset your root password in RHEL, CentOS, and Fedora.

What You’ll Need

  • Physical or console access to the server
  • Ability to reboot the machine
  • Basic familiarity with Linux command line

Step 1: Access GRUB Bootloader

  • Reboot the system
  • When you see the GRUB menu, use arrow keys to select your boot kernel.
  • Press e to enter edit mode.

Step 2: Edit Kernel Parameters

  • Find the line starting with linux or linux16.
  • At the end of this line, add:
  • rd.break (for most Red Hat-based systems)
  • Alternatively, in RHEL 9, you may use rw init=/bin/bash for direct rescue mode.

Step 3: Boot to Rescue/Shell Mode

  • Press Ctrl+X or F10 to boot
  • Wait for the system to enter the emergency shell prompt

Step 4: Remount and Chroot

Next, give the system write access and switch root using these commands:

mount -o remount,rw /sysroot
chroot /sysroot

Step 5: Change Root Password

Now, run the following command to set a new password:

passwd

Enter and confirm your new password.

Step 6: Prepare SELinux Relabeling

This step ensures proper SELinux context for the new password:

touch /.autorelabel

Step 7: Exit and Reboot

  • Type exit twice to leave chroot and emergency shell
  • The system will reboot and perform SELinux relabeling (may take a few moments)

Step 8: Login With New Root Password

  • At the login prompt, use your new root credentials
  • Verify shell access and sudo functionality

Conclusion

You’ve now learned how to recover root password in Red Hat-based Linux systems using GRUB, rescue mode, and SELinux strategies. Bookmark this guide and add your own screenshots to maximize clarity for readers and exam takers.

Similar Posts

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.