Wednesday, 5 February 2020

RHEL 8 / CentOS 8 recover root password

https://linuxconfig.org/redhat-8-recover-root-password

1. Boot to the GRUB menu and enter the edit mode. Use your arrows to navigate to the the menu item you would normally boot your RHEL 8 Linux system from. Press e to start editing the selected menu item.


2. Perform a break at an early stage of the boot process by typing rd.break at the end of the line starting with kernel=. Once ready press CTRL+X to start the RHEL 8 boot process.


3. Check write access on the /sysroot mount point. By default this mount point is mounted only with the read-only (ro) access. Execute:
switch_root:/# mount | grep sysroot


 4. Remount the sysroot directory with read & write access. To do so execute:
switch_root:/# mount -o remount,rw /sysroot/
switch_root:/# mount | grep sysroot



5. Enter chroot system by executing:
switch_root:/# chroot /sysroot

6. Use the passwd command to set a new root password. Please note that when typing a new password the characters you type will not be visible. Simply keep typing.



7. Force file-system relabeling by executing the following command:
# touch /.autorelabel



 8. Exit the chroot system by executing the exit command:
# exit




9. Logout to continue the normal boot:
switch_root:/# logout




10. Wait for the file-system relabeling to complete. Depending on your system speed and number of files this might take some time. Be patient.

11. Login with your new root password.