The root password is forgotten. It vital to recover it without reinstalling the RHEL and CentOS . The recovery process include to access any documentation. It is recommended to write those commands separately. On a piece of paper so that recovery process will complete successfully. The tutorial includes the command. The root user permission is necessary. Whenever running any commands and tools. Please follow all the steps carefully.

Step-1 : Select the Linux Kernel and Edit the Linux kernel Parameters

Press up and down key simultaneously so that you will access the GNU-GRUB2 menu. From the first option hit E to edit the first grub menu.

Also Read High Performance Managed WordPress Hosting Review

After editing the GNU-GRUB2 menu find the lines started with linux16 and hit End button to go to the last line and add rd.break to it.

After add these lines hit Ctrl + X to boot.

Step-2 : Recover the root password

First mount the /sysroot directory

# mount -o rw,remount /sysroot

Then Change the root directory to /sysroot

# chroot /sysroot

After that change the root password and you will be prompted to add the new password make sure it is strong.

# passwd root

Step-3 : Auto Label the SELinux context to /etc/passwd file

Finally after running the passwd command the Linux need to be set the new password by relabeling to the /etc/passwd file and it is necessary for running with correct SELinux context.

# touch /.autorelabel

It takes several minutes depending on your system CPU and Hard Drive speed.

Also Read  How to Configure Awstats on CentOS 7 / RHEL 8

Step-4 : Boot with the graphical user interface target

It is vital to run the Linux distribution with the graphical user interface by using the

# systemctl set-default

When done type two times exit and exit command to exit from chroot jail and to reboot the system.

Congratulations now you have reset the forgotten password without reinstalling the CentOS and RHEL.