Resetting the Root Password in CentOS 8

  • Restart the server and press the e button in the GRUB start menu to edit the startup entry.
  • Add the following parameters at the end of the line starting with linux ($root)/:

rd.break enforcing=0

  • The line should now look something like this:

linux ($root)/vmlinuz-4.18.0-80.11.2.el8_0.x86_64 root=/dev/mapper/centos-root\ ro crashkernel=auto resume=/dev/mapper/centos-swap rd.lvm.lv=centos/root rd.l\ vm.lv=centos/swap rd.break enforcing=0

The parameter rd.break causes the boot process to be interrupted before control is passed from initramfs to systemd. This allows the initramfs prompt to be used for command input, and the parameter enforcing=0 puts SELinux in permissive mode. This saves the later – and possibly very time-consuming – relabeling of the file system, which would be necessary if SELinux were switched off.

  • Press Ctrl+x to boot the system with the changed parameters, and the switch_root prompt of initramfs will be displayed.
  • Since the filesystem under /sysroot/ is mounted with read-only permissions, you must first remount it with write permissions:

switch_root:/# mount -o remount,rw /sysroot

  • Now switch to a chroot environment:

switch_root:/# chroot /sysroot

The prompt changes to sh-4.4#.

  • Now you can change the password via passwd:

sh-4.4# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

touch /.autorelabel

  • To leave the chroot environment, type the following command:

exit

  • Reboot the server. To do this, enter the following command:

reboot