What if, root or superuser password is lost or forgot in RedHat/CentOS 7 Linux? This is the quick guide or method to reset forgotten root password without any additional recovery tools. But you need to have physical access of the system. I have tested this on RedHat 7 Linux and the same steps can be followed to reset lost or forgotten root password on CentOS 7 Linux as well.
1. Boot your system in GRUB 2 menu
We can see the GRUB 2 menu when system boots up, press ESC to intercept and enter into GRUB 2 Menu.
2. Editing GRUB 2 Menu
Press e to edit GRUB 2 menu, you can see the similar screen as below. Scroll down and search linux16 or linuxefi (if your system is efi enable) and move to the end of the line. Add the string init=/bin/bash to the end of line after giving space. Also remove the rhgb quiet from that line.
3. CTRL+x to boot in single user mode.
Once you have done that change, press Ctrl-x to accept the changes it will boot into runlevel 1 (single user mode).
4. Run load_policy to load the installed policy file into the kernel.
5. Use mount command to remount the root filesystem in read-write mode
6. Change root password
Now, we can change root password with passwd command as below.
7. Run the exec /sbin/init command
System boots up, you can try login with newly recovered or reset root password (if root user is enabled).