How To Reset Root User Password In CentOS/RHEL 8

Sometimes, system administrator forgets the root password and end up with a requirement to reset the root password. You can recover the password without any additional tool. This article provides you step by step instruction to recover/reset the CentOS/RHEL 8 root password.

Steps to Reset Root User Password In CentOS/RHEL 8

Reboot the server and when the GRUB boot menu comes, choose the Kernel version you want to boot and press e to edit the selected boot entry.

Next screen you will see the Kernel boot parameters. Find the Kernel parameters ro:

Now, change ro to rw and add the extra parameters init=/sysroot/bin/sh as shown as below:

After changing the parameters, as shown above, press Ctrl+x to enter into the single-user mode.

From single user mode execute the following command to mount root (/) file system in read/write mode.

# chroot /sysroot

Now, you are good to reset the root password using mention command.

# passwd root

After updating the root password, enter the following command to enable SELinux relabeling on reboot :

# touch /.autorelabel

Finally, you can reboot the CentOS server to normal mode.

# exit
# reboot

You need to wait for some time till SELinux relabeling process complete. It will take time depends upon the filesystem size.

Once, the relabeling process completed, you can login into your server.

Enjoy it!

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.