Home Linux DistributionsCentOS How To Reset Root User Password In CentOS 8 / RHEL 8
reset root user password in CentOS 8 and RHEL 8 editions

How To Reset Root User Password In CentOS 8 / RHEL 8

By sk
757 Views

This brief tutorial explains how to reset Root user password in CentOS 8 and RHEL 8 server editions. This quick tip will be helpful when you lost the root user's password and want to recover it without any additional recovery tools. Since you must log in to single user mode to recover the password, you should have physical access to the system. If the server is hosted somewhere else, you might need your hosting provider's help.

Reset Root User Password In CentOS 8 / RHEL 8

I tested this guide on CentOS 8 server, however it should also work in RHEL 8 server as well.

Power on the CentOS server. When the GRUB boot menu appears, choose the Kernel version you want to boot and press e to edit the selected boot entry.

Edit grub boot menu entry in centos 8

In the next screen, you will see the Kernel boot parameters. Find the kernel parameter ro:

find 'ro' kernel parameter in grub entries in centos 8

…and change ro to rw and add an extra parameter init=/sysroot/bin/sh with space-separated as shown below. To put this in simple terms, replace 'ro' parameter with 'rw init=/sysroot/bin/sh'. Please mind the space between "rw" and "init=/sysroot...".

replace ro with rw parameter

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

From the emergency mode, enter the following command to mount root (/) file system in read/write mode.

chroot /sysroot/

mount root file system in read, write mode in centos 8

Now, change the root user password using command:

passwd root

Enter the password twice. I recommend you to use any strong password that contains numbers and special characters.

change root user password in centos 8

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

touch /.autorelabel

enable SELinux relabeling on reboot in centos 8

Finally, type the following commands to apply the changes and reboot the CentOS server to normal mode:

exit
reboot

Wait for SELinux relabeling process to complete. It will take some time depending upon the filesystem size and speed of your hard drive.

SELinux filesystem relabeling process

Once the filesystem relabeling is completed, you can log in to your CentOS 8 server with new root password:

Log in to centos 8 server


Suggested read:


Hope this helps.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

1 comment

Jalal February 20, 2020 - 9:29 am

Hi,
Very nice and useful article.
Thanks a lot

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More