If you forget or want to recover the root password of redhat /CentOs machine. You do not need to be panic. It’s possible to break or reset the root password in case if you forget it.
Step 1 :
Reboot your machine, before booting Press ‘e’ to interrupt the booting process of your machine.
Then look for a line linux 16 write rd.break between initrd16 and Press Ctrl ‘x’ to execute it.
Step 2 :
Now system will be in emergency mode, next step is run a command mentioned below
mount –o remount,rw/ sysroot
This command is used as by default sysroot is in read only mode. We changed it to read write mode.
Step 3 :
Change the root
Step 4 :
It will ask you to change the password after running above command then change the root password here.
This command will disabled the SElinux
After all, Last Step is to load the changes to SElinux
Command is touch /.autorelabel
Step 6 :
You will have to exit two times then system will reboot, try to login with your new password. Enjoy