Home > Article > Computer Tutorials > How to reset forgotten root password on RHEL-based Linux distributions such as Fedora and Rocky?
This article will guide you through simple steps to reset the forgotten root password in RHEL-based Linux distributions such as Fedora, CentOS Stream, Rocky and Alma Linux.
First, reboot the system, then select the kernel you want to boot in the grub boot menu (usually the first option), then press the corresponding key on the keyboard.
On the next screen you will see the following kernel boot parameters, here find the line starting with ro
and add the parameter rd.break
at the end as shown in the picture , and then press the Ctrl x
key.
On the next screen you will enter emergency mode, now press Enter
to enter the shell prompt. Now, make sure you remount the sysroot
directory with read and write permissions. By default, it is installed in read-only mode, indicated by ro
.
# mount | grep sysroot
Now remount the sysroot
directory with read and write permissions and confirm the permissions again.
Please note that this time the permissions have been changed from ro
(read only) to rw
(read and write) as shown.
# mount -o remount,rw /sysroot/ # mount | grep sysroot
Next, use the following command to mount the root file system in read-write mode.
# chroot /sysroot
Next, use the passwd
command to reset the root password with the new password and confirm.
# passwd
At this point, you have successfully reset the root user password. The only remaining part is to re-mark all files with the correct SELinux context.
# touch /.autorelabel
Finally, enter exit
and log out to start the SELinux relabeling process.
This usually takes a few minutes, once complete, the system will reboot and prompt you to log in as root using your new password.
Resetting a forgotten root password in RedHat-based Linux distributions is a relatively simple process that involves accessing the system during boot, modifying kernel parameters, and resetting the password using specific commands.
The above is the detailed content of How to reset forgotten root password on RHEL-based Linux distributions such as Fedora and Rocky?. For more information, please follow other related articles on the PHP Chinese website!