We have got many changes in Red Hat Enterprise Linux / CentOS , one of the many changes GRUB 2 version. Reset the password through single user mode we are using in RHEL 5 and RHEL 6 version but here it will different from older versions.
Below is the new procedure to reset the root password , if we forget or lost our root password in CentOS or RHEL latest version like 7 , 8 and 9 .
Use below procedure carefully and mistake can make your machine unstable, first try l test machine on your own risk.
Show Forget root password and reboot the CentOS server
Here I am showing the screen of trying to login through GUI in Linux box and not getting success in login through GUI , same will be implement as command line interface.
GRUB 2 Edit Menu Option
In new version of GRUB , we will not use single-user mode , In GRUB2 we have the Rescue Mode / Emergency mode in new version .
First start or reboot your machine and wait for GRUB 2 booting menu screen , it will show in image below and press “e” edit key to edit the grub 2 menu option after grub 2 loaded .
In editing GRUB 2 menu option go down . Search “linux16” or “linuxefi” line using the up and down
arrow keys and go to the end of the line and add “rd.break” keyword .
After set rd.break key word in the end of the line press ctrl+x to boot or start the process.
Reset the root password
Now the Emergency shell mode or rescue shell mode will available for reset the password .
First we will remount the sysroot file system in read and write mode . Then use chroot to got into a chroot jait at /sysroot through below commands .
# mount –o remount,rw /sysroot
# chroot /sysroot
Now we will git passwd command in the command line and press same password twice for reset root password.
In the Last point make sure that all unlabled files ( including shadow ) get relabled during boot with below command.
# touch /.autorelabel
Type exit two time s after run autoreleble activity. The first will exit the chroot jail and the second will exit the initramfs debug shell.
Find below all the commands history which we use to reset the password.
I have got root screen .. 🙂