How to Reset Forgotten Root Password in RHEL/CentOS & Fedora

This article will guide you through simple steps to reset forgotten root password in RHEL-based Linux distributions such as CentOS 8 and Fedora 35/34.

Resetting the forgotten root user password generally requires a few easy instructions that will guide you to reset the root password and you will thereafter be able to log in using the new password.

Reset Forgotten Root Password in RHEL/CentOS & Fedora

First, restart your system, and at the boot grub menu choose the kernel (mostly the first option) you wish to boot into and press the key 'e' on your keyboard.

RHEL 8 Boot Menu
RHEL 8 Boot Menu

On the next screen, you will see the following kernel boot parameters, here find the line that starts with kernel= and add the parameter rd.break at the end as shown and press Ctrl + x keys.

Append Kernel Parameter
Append Kernel Parameter

On the next screen, you will land into emergency mode, here press Enter key to get into the shell prompt. Now, make sure to confirm that you remount the sysroot directory with read and write permissions. By default, it is mounted with read-only mode indicated as ro.

# mount | grep sysroot
Confirm Sysroot Directory Permissions
Confirm Sysroot Directory Permissions

Now remount the sysroot directory with read and write permissions and confirm the permissions again. Note that this time, the permissions have changed from ro (read-only) to rw (read and write) as shown.

# mount -o remount,rw /sysroot/
# mount | grep sysroot
Mount Sysroot Directory
Mount Sysroot Directory

Next, mount the root file system in read and write mode using the following command.

# chroot /sysroot

Next, use the passwd command to reset the root password with the new password and confirm it.

# passwd
Reset Root Password
Reset Root Password

At this point, you have successfully reset your root user password. The only remaining part is to relabel all of the files with the accurate SELinux contexts.

# touch /.autorelabel
Enable SELinux Relable
Enable SELinux Relable

Finally, type exit and then log out to start the SELinux relabelling process.

SELinux Relabelling Process
SELinux Relabelling Process

This generally takes a few minutes and once done, the system will reboot and prompt you to log in as the root user with the new password.

RHEL 8 Login
RHEL 8 Login

And that’s how you would reset a forgotten root password in RHEL/CentOS 8 and Fedora 35/34 Linux distributions.

If you read this far, tweet to the author to show them you care. Tweet a thanks
Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

64 thoughts on “How to Reset Forgotten Root Password in RHEL/CentOS & Fedora”

  1. I followed the same, I had a problem. First, I have two Red Hat Linux servers. Second, I was able to recover the password for the one with OS 5.1.x. I was not able to do it on the Red Hat Enterprise Linux 6.4, it’s an appliance with nGeniusOne from Netscout Systems.

    In this box, I was able to boot to the GNUB, but when I type “a” to modify the kernel. Nothing pops up. It keeps showing the OS until I hit “Enter” and it boots to complete. Only one item as there was no previous updates. Can anyone help out?

    Reply
  2. That was awesome, I followed the same and was able to reset my CentOS password which had stayed blocked for close to a week

    Reply
  3. Wow!!, thats awesome, I was able to reset my REDHAT 5.5 password by following your tutorial. I am soo happy. Thank you very much and keep it up.

    Reply
  4. I was locked out of centos 6.6 as I had lost my password details by following your easy step recovery procedure I was able to create another password. Thankyou for this very useful information.

    Reply
  5. Accidentaly i changed the owner root to oroot in the password file at /etc/passwd.
    When u tired to logon the system said that root doesn’t exist. How can i change back user oroot to root in the passwd file?

    Thanks

    Reply

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.