Forgot your RHEL 7 or CentOS 7 Linux root password? Do you want to recover it? Follow 7 easy steps to gain root user access.
Note: This procedure must be performed from a console session. The system is using the default grub2 bootloader and grub is not being password protected and this procedure cannot be accomplished over any SSH remote session. To see the grub bootloader boot options is mandatory and using the procedure below, it can only be done through a console session, not with an ssh session
Step one is to reboot the system and edit the grub2 parameters. Press ‘e’ before the menu times out and boots normally.
Look for a line that mentions linux16 (or linuxefi if you are using UEFI bios). You may need to use the arrow keys to scroll down.
At the end of the linux16 or linuxefi line, find and replace the rhgb quiet parameters with rd.break enforcing=0 as shown below
After the above changes hit Ctrl+x. to reboot and see the effects. The system should boot into the root system.
Remount system as read/write
Enter the following command to remount the sysroot filesystem as read/write:
mount -o remount,rw /sysroot
Change root to sysroot
Now we using chroot command into the sysroot, using the following command: chroot /sysroot
Change the password
We can use the passwd command to change the root password.
Exit from the shell and remount sysroot
Enter the following command to bring control back to the switch_root:/# prompt:
And execute the command to remount the sysroot filesystem as read-only once again:
mount -o remount,ro /sysroot
Exit session and reboot
After all the processes enter the exit command and the system will prompt for login/password.
You can login system with a new password which you set in step 5.