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.

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.

CentOS-6 Note: Due to an upstream SELinux bug in early versions of CentOS-6, the root password cannot be reset on a fresh install of CentOS-6 without an additional step. Booting with "selinux=0" appended to the grub kernel line, or doing "setenforce 0" after logging in and before attempting to reset the password are work-arounds. This is not required on CentOS 6.8 or higher as the bug has already been fixed although I do not know in which version it was present nor which has the fix. It's most likely that only very early versions of CentOS 6 had this bug.

For CentOS-7 please follow the upstream instuctions:

On CentOS-7, 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

TipsAndTricks/ResetRootPassword (last edited 2017-01-25 18:11:03 by TrevorHemsley)