How to Reset Forgotten Root Password in Redhat 8/CentOS 8

Reset Forgotten root Password in CentOS 8

First, reboot or power on your Redhat 8/CentOS 8 system. Select the kernel you want to boot into. Next, press ‘e’ on the keyboard to interrupt the boot process and make changes.

Redhat 8/CentOS 8 Boot Menu

On the next screen, locate the ro (read-only) kernel parameter as highlighted below.

Locate Kernel Parameter

Replace the kernel parameter ro with rw and append an extra kernel parameter init=/sysroot/bin/sh. In a nutshell, simply replace the kernel parameter ro with rw init=/sysroot/bin/sh.

Replace Kernel Parameter

Once done with making the changes, hit Ctrl + X combination on the keyboard to enter single-user mode.

Next, run the command below to mount the root file system in read and write mode.

:/# chroot /sysroot
Mount Root File System

You can now change the root password by executing the command:

:/# passwd root

Provide a new root password and confirm it. For best practice select a password with a combination of uppercase, lowercase, numerical and special characters to boost password strength.

Reset Root Password

Next, run the command below to enable SELinux relabelling.

:/# touch /.autorelabel
Enable SELinux Relabelling

To apply the changes, exit and reboot the Redhat 8/CentOS 8 system.

:/# exit
:/# reboot
Reboot Redhat 8/CentOS 8 System

Upon reboot, the SELinux relabelling process will commence. Give it about 3 minutes.

SELinux Relabeling Process

When the relabeling process is done, the system will reboot and thereafter, you will be get logon screen and you can able to login successfully with the new password which you just set