• Contact: +91-08069248012

How to Reset Centos Root Password


If you have forgotten the root password it is possible to set a new one as follows:

Interrupt the boot at the GRUB stage and boot to runlevel 1, AKA single user mode. Interrupt GRUB by typing a character such as "space" then append to the kernel line by typing "a", backspacing through "rhgb quiet" and appending " 1".

rhgb quiet 1

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 will boot to the multi-user mode defined in /etc/inittab.

CentOS-6 Note: 

Due to an upstream SELinux bug 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 corrected by applying already-released errata updates.

CentOS-7 Note: 

the procedure is now different again and you should follow the upstream instructions https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sec-Terminal_Menu_Editing_During_Boot.html#sec-Recovering_Root_Password

If SELinux is enforcing 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