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.
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.
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
# mount | grep sysroot
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
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.
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
Finally, type exit and then log out to start the 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.
And that’s how you would reset a forgotten root password in RHEL/CentOS 8 and Fedora 35/34 Linux distributions.
64 thoughts on “How to Reset Forgotten Root Password in RHEL/CentOS & Fedora”
Hi, I’m taking an intro to Linux class and I was that dummy who forgot his password to get into the linux shell today. I read here that the SElinux context can be accurately implemented with
# touch /.autorelabelis there a reason why it would be something else?
Hi All, I am new to Linux. I tried to break my root password with above method. but when i interupt the grub, and type
a, nothing comes up. After sometime it just loads the default OS version, but when i give
a, and use different sets of commands, I am able to change the root password. Can some one tell what am i missing in the above method. I am using centos 7 in my VM.
In CentOS 6 version, you need to press
ato enter to single user mode, while in CentOS 7, you should use
eto enter into single user mode. I hope it clears your doubts..
Here is the guide on How to Reset or Recover Forgotten Root Password in CentOS 7
yes Ok. Thankyou.
Same here as @ravi. It’s giving me “give the root password for maintenance.“. Version 2.6.32-358.0.1.el6.i686
Thanks for sharing, let me try the same instructions on my CentOS 6, will get back to you with solution.
It is giving the massage that give the root password for maintenance.
i am not able to attach the screenshot
Which version of Linux distribution are you using? mostly it wouldn’t ask for password in maintenance mode, either you doing wrong, follow the instructions carefully..