Resetting a Forgotten Root Password
If you have forgotten the root password it is possible to set a new one as follows:
CentOS-6 instructions (also for CentOS 5):
Interrupt the boot at the GRUB stage when you see the menu that says "Booting CentOS (2.6.32-...) in X seconds" and boot to runlevel 1, AKA single user mode by doing the following.
- Interrupt GRUB by hitting the Esc key then append to the kernel line by typing "a"
- Backspace and delete "rhgb quiet" (if present)
- Append a space followed by the digit 1
- Press Enter to boot up
This will give you a root shell and not a login prompt. From there you can use the "passwd" command to set a new root password.
Other user passwords can be reset, and other administrative tasks can be performed as well. Exiting the single user root shell by pressing Ctrl-D will boot to the multi-user mode defined in /etc/inittab.
For CentOS-7 and CentOS-8 please follow the upstream instuctions: https://www.redhat.com/sysadmin/recover-root-passwd
If SELinux is enforcing and the upstream instructions tell you to do so, then do not forget to relabel your filesystem afterwards or you will not be able to login until you reboot and repeat the instructions and include the autorelabel