RedHat / CentOS 7 – Reset Root Password

If you’ve lost or forgotten the root password of your RH/CentOS 7 box, here’s how to reset it.

Reboot, at the Grub menu press ‘e’ before the timeout occurs.

Find the ‘linux16’ line and append the following to the end of it:

init=/bin/bash

Press Ctrl-x to boot with the new configuration. This will boot into a Bash shell as the first process. Your root directory will be read-only at this point, to fix that:

mount -o remount,rw /

Then change the password:

passwd

Finally, due to the SELinux policy in v7, you’ll need to do the following:

touch /.autorelabel

Then reboot and enjoy!

Advertisements