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

WBOY
Release: 2024-03-19 19:43:15
forward
1204 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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

# passwd
Copy after login

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
Copy after login

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!

Related labels:
source:mryunwei.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template