root password recovery

In a stable system where no new kernels or OSes are installed we will rarely have to modify GRUB2. But it might come in handy at some point if we forget the root password and our user does not have sudo rights to reset it. In such a case we can proceed in 2 different ways: booting with installation media or with GRUB2.

If we decide to use the installation media we would:

1. boot the system from the CD/DVD or other installation media

2. choose “Troubleshooting” in the menu

3. choose “Rescue RHEL system

4. chroot /mnt/sysimage

5. change root password with passwd

6. skip the SELinux relabeling of the disk with rm -­f /.autorelabel

7. reboot

 

If we use the GRUB2 option we would:

1. boot the system and get to the GRUB2 menu

2. select the normal boot entry and press “e” to edit it

3. remove the “rhgb quiet” words and add “rd.break enforcing=0”

4. press Ctrl+X to boot the system

5. mount ­-o remount,rw /sysroot

6. chroot /sysroot

7. passwd

8. rm -­f /.autorelabel

9. mount -­o remount,ro /

10. exit chroot

11. exit prompt

12. restorecon /etc/shadow

<< systemd