Reset root Password

How to reset a root password

If you have forgotten your root password on a Red Hat Enterprise Linux based server, you can reset your root password following the example below.

Reset root password on a RHEL 8 system

If you have forgotten your root password on RHEL 8 based system, then you can reset the root password quite easily.

First, if you have an account with "sudo" privileges, the you can simply issue the command: "sudo passwd root".

$ sudo passwd root
[sudo] password for john: 
Changing password for user root.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

However, if you do not have an account available with "sudo" privileges, then you will need to follow the following procedure below.

Reset root password on RHEL 8

The following procedure can be used for any RHEL 8 based systems such as as CentOS 8 or Rocky Linux.

The first step to changing the root password is to reboot the system and access the "GRUB" boot-loader menu. This menu is normally displayed when your system first starts.


From the GRUB menu, highlight the very top entry, this will be your most recent version of your system.

Once you have highlighted the entry using the cursor keys, press "e" to edit this entry.

RHEL 8 GRUB Menu Edit

You will now see a screen similar to the one above. Next, find the line that begins "linux" and scroll to the very end of the line.

Next, add the following parameter: rd.break to the end of this line as per the image above.

Once you have made this change, press Ctrl -X to start your system.

Shell Prompt

You should now see a screen similar to the one below displaying a shell command prompt.

RHEL 8 recovery Mode

At this command prompt, you need to type the following commands:

mount -o remount,rw /sysroot
chroot /sysroot

The above command will enable you to change the "root" password. below is a screen shot of this being carried out.

RHEL 8 reset password

You will be prompted to enter a new root password and then confirm the entry.

SELinux relabeling

Once you have reset the root password, you need to run the following commands to relabel SELinux at reboot.

touch /.autorelabel

After you have typed "exit" twice, your system will reboot and you will see a message similar to the output below:

RHEL 8 SELinux relabel

Login now with root password

Once the above has finished running a relabel, you will be taken to the normal login prompt. Here you can now login with the new password set for the "root" account.

RHEL 8 Login Screen