Home  >  Article  >  Computer Tutorials  >  How to reset forgotten root password on RHEL-based Linux distributions such as Fedora and Rocky?

How to reset forgotten root password on RHEL-based Linux distributions such as Fedora and Rocky?

WBOY
WBOYforward
2024-03-19 19:43:151186browse

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.

How to reset forgotten root password on RHEL-based Linux distributions such as Fedora and Rocky?

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.

How to reset forgotten root password on RHEL-based Linux distributions such as Fedora and Rocky?

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

How to reset forgotten root password on RHEL-based Linux distributions such as Fedora and Rocky?

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

How to reset forgotten root password on RHEL-based Linux distributions such as Fedora and Rocky?

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

How to reset forgotten root password on RHEL-based Linux distributions such as Fedora and Rocky?

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

How to reset forgotten root password on RHEL-based Linux distributions such as Fedora and Rocky?

Finally, enter exit and log out to start the SELinux relabeling process.

How to reset forgotten root password on RHEL-based Linux distributions such as Fedora and Rocky?

This usually takes a few minutes, once complete, the system will reboot and prompt you to log in as root using your new password.

How to reset forgotten root password on RHEL-based Linux distributions such as Fedora and Rocky?

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!

Statement:
This article is reproduced at:mryunwei.com. If there is any infringement, please contact admin@php.cn delete