RHEL 8 / CentOS 8 recover root password

This article provides step by step instructions on how to recover/reset lost or forgotten RHEL 8 / CentOS 8 Linux root administrative password. To recover the root password you will first boot to the GRUB menu and perform a break at early stage of the boot process. Afterwards, you will remount the sysroot directory with read & write access and change the root password on RHEL 8 / CentOS 8 by using the passwd command to set the new root password.

In this tutorial you will learn:

  • How to perform a break at an early stage of the boot process.
  • How to remount root partition with read/write access.
  • How to change root password.
  • How to force filesystem relabeling.

Successfully recovered lost root administrative password on RHEL 8 Linux Server/Desktop

Successfully recovered lost root administrative password on RHEL 8 Linux Server/Desktop.

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System RHEL 8 / CentOS 8
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to recover RHEL 8 / CentOS 8 root password step by step instructions

  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.


    GRUB boot menu on RHEL 8 Linux

    GRUB boot menu on RHEL 8 Linux.

  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.
    Editing GRUB boot menu to interrupt  boot process.

    Editing GRUB boot menu to interrupt the 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
    
    /sysroot/ is mounted as read only. Note the ro as per the mount command output.

    /sysroot/ is mounted as read only. Note the ro string as per the mount command output.

  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
    


    /sysroot/ is now mounted with read and write access

    /sysroot/ is now mounted with read and write access. Note the rw string as per the mount command output.

  5. Enter chroot system by executing:
    switch_root:/# chroot /sysroot
    
    Enter chroot on RHEL 8 Linux system

    Enter chroot on RHEL 8 Linux system. This will provide you with a regular shell.

  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.
    Set new root password using passwd command

    Set new root password using the passwd command.

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

    Force file-system relabeling on RHEL 8 Linux system.

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


    Exit chroot system

    Exit the chroot system.

  9. Logout to continue the normal boot:
    switch_root:/# logout
    
    Logout to continue with a regular boot process

    Logout to continue with the regular boot process.

  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.
    File-system relabeling in progress.

    File-system relabeling in progress.

  11. Login with your new root password.
    RHEL 8 / CentOS 8 login TTY console screen.

    RHEL 8 / CentOS 8 login TTY console screen.