For RHEL / CentOS 7 the steps are completely different and a little trickier than it was in older RHEL versions.
In this article I will show you the steps to reset your root password using rd.break
NOTE: I hope you have console access to your Linux box as without this you cannot reset the password using an ssh client.
Reboot your Linux box to the boot menu as shown below
Edit the primary boot loader in the GRUB menu as for me you can see I only have one kernel installed to I will press “e” to enter into edit mode
which will bring you below menu
if [ x$feature_platform_search_hint = xy ]; then
search –no-floppy –fs-uuid –set=root –hint-bios=hd0,msdos1 –hint-efi=hd0,msdos1 –hint-baremetal=ahci0,msdos1 –hint=’hd0,msdos1′ af0be92e-0721-46b8-affd-60f9baff3652
search –no-floppy –fs-uuid –set=root af0be92e-0721-46b8-affd-60f9baff3652
linux16 /vmlinuz-3.10.0-693.el7.x86_64 root=/dev/mapper/rhel-root ro rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet net.ifnames=0 systemd.unit=emergency.target
Press Ctrl-x to start, Ctrl-c for a command prompt or Escape to
discard edits and return to the menu. Pressing Tab lists
Look out for the kernel line i.e. below one for me
Remove “rhgb quiet” and add “rd.break” in the last as shown below
rd.break will stop the boot procedure before mounting the filesystem wherein all the supporting modules are loaded and with a valid shell.
Press “Ctrl +x” to boot your box with the new changes
As you see now you have a shell and you were not prompted for root password
Next you must remount your filesystem with read write permission as currently you have logged in with read only mode for root filesystem
Next we need to move the content of sysroot from chroot to normal root environment
Now you are ready to set your password. You can use below command to set the password. Replace “mynewpassword” with your new password followed by the username i.e. “root“
Next we need to tell selinux that it needs to do relabelling or else our changes will be gone after reboot, for this create a new autolabel file using below command
You are all done now. Next press “Ctrl +D” twice to exit the window followed by a reboot
Next once your node is UP, try to login with your new password