How to Change or Reset Forgotten Root Password in RHEL 8

You can never really relate to the priceless beauty and performance of RHEL 8 Linux operating system distribution until you have given it a try. Its user interface is always scaling to better visual appeal, its multi-monitor handling technique is one of a kind, and its security model speaks for itself.

The only thing that can come between an RHEL user’s full exploration of this Linux distribution is human nature. Human nature will convince us to create/set a one-of-a-kind root password on our Linux systems and be responsible for displacing the same unique password.

It is one thing to change a root password and another thing to reset a root password. Changing a root password is straightforward because you still have the old root password in memory. Resetting the root password is another story. It implies that you have no clue or hint regarding this password.

Forgetting the root password forces many users to re-install their RHEL Linux systems, not knowing there is a valid fix.

Changing RHEL 8 Root Password

To successfully change the root password on your RHEL 8 system, you must remember your current root password. A common reason for changing the root password is if you feel like your current root password has been compromised.

The first step is to open the Linux terminal and switch to the root user.

$ sudo su

Next, type the command passwd on your terminal and follow the resulting prompts to successfully change and update the root user password.

# passwd
Change Root Password in RHEL 8
Change Root Password in RHEL 8

The above screen capture confirms the success of the passwd command execution in changing the root user’s password.

Resetting RHEL 8 Forgotten Root Password

This step assumes that we have no idea/hint about the RHEL system’s root user password. To achieve our password reset objective, we first need to restart our RHEL OS and access the Grub boot menu.

Restart your OS and press the [Esc] key or the keyboard key that is associated with interrupting the boot-up process of your OS. Your keyboard action should lead to an interface similar to the following screen capture:

RHEL 8 Boot Grub Menu
RHEL 8 Boot Grub Menu

On your computer keyboard, press the [e] key, which will display your system’s associated kernel boot parameters. Take note of the line that starts with the word linux and ends with the word quiet.

RHEL 8 Boot Parameters
RHEL 8 Boot Parameters

At the end of this line, add rd.break so that it looks like the following screen capture.

Edit RHEL 8 Boot Parameters
Edit RHEL 8 Boot Parameters

On your keyboard, press [Ctrl]+[x] to implement the parameter changes. You will be redirected to a switch_root command-line interface.

RHEL 8 Emergency Mode
RHEL 8 Emergency Mode

At this point, your filesystem needs to be writable, run the following command to remount it.

# mount -o remount, rw /sysroot 
RHEL 8 Mount Root Filesystem
RHEL 8 Mount Root Filesystem

We now need to access the chroot environment by running the following command.

# chroot /sysroot
RHEL 8 Filesystem Switch
RHEL 8 Filesystem Switch

As you have noted, the terminal instance has changed from switch_root to sh-4.4. We can now use this prompt to reset the root user password.

# passwd

Follow the provided steps to successfully reset the root password in RHEL 8.

Reset Root Password in RHEL 8
Reset Root Password in RHEL 8

The next system boot needs SELinux relabeling enabled.

# touch /.autorelabel
RHEL 8 SELinux Relabeling
RHEL 8 SELinux Relabeling

Exit chroot and switch_root environments.

# exit
# exit
RHEL 8 Exit Chroot
RHEL 8 Exit Chroot

The system will automatically reboot after SELinux relabeling process is done with its execution. To verify the new root user password, switch to the terminal and sequentially execute the following commands.

$ su

Enter your new root user password.

# whoami

The output should be root.

RHEL 8 Root Login
RHEL 8 Root Login

With this article guide, changing the root user password might be something you were bound to figure out on your own but resetting the root user password will save you from having to forcefully reinstall your RHEL operating system.

Got something to say? Join the discussion.