How to change the root password on CentOS 7 with SELinux enabled

Reboot the system and when you see the Grub menu press 'e'.

Find the line starting with the "linux16".

Replace the "ro rhgb quiet" with "rw init=/sysroot/bin/bash" (or "rw init=/sysroot/bin/sh").

Press Ctrl+x.

When you see the command prompt, type:

# chroot /sysroot
# passwd
# touch /.autorelabel
# sync
# exit
# reboot

If you don't make the file ".autorelabel" you will not be able to login if SELinux is enabled.

Comments