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.
Software Requirements and Conventions Used
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
- 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.
- Perform a break at an early stage of the boot process by typing
rd.break
at the end of the line starting withkernel=
. Once ready pressCTRL+X
to start the RHEL 8 boot process. - 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
- Remount the
sysroot
directory with read & write access. To do so execute:switch_root:/# mount -o remount,rw /sysroot/ switch_root:/# mount | grep sysroot
- Enter chroot system by executing:
switch_root:/# chroot /sysroot
- 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. - Force file-system relabeling by executing the following command:
# touch /.autorelabel
- Exit the
chroot
system by executing theexit
command:# exit
- Logout to continue the normal boot:
switch_root:/# logout
- Wait for the file-system relabeling to complete. Depending on your system speed and number of files this might take some time. Be patient.
- Login with your new root password.