Home CentOS How To Reset Root User Password In CentOS 8, RHEL 8, AlmaLinux 8, Rocky Linux 8

How To Reset Root User Password In CentOS 8, RHEL 8, AlmaLinux 8, Rocky Linux 8

Reset Forgotten Root Password In CentOS, RHEL, AlmaLinux, Rocky Linux

By sk
Published: Last Updated on 3.4K views

This brief tutorial explains how to reset root 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 root password 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 password in CentOS 8, RHEL 8

I tested this guide on a CentOS 8 server, however it should also work in RHEL 8 an its clones like AlmaLinux 8 and Rocky Linux 8 as well.

Step 1: 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
Edit grub boot menu entry in centos 8

Step 2: 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
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
Replace ro with rw parameter

Step 3: 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
Mount root file system in read, write mode in centos 8

Step 4: 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.

Reset or change root password in centos 8
Reset or change root password in centos 8

Step 5: 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
Enable SELinux relabeling on reboot in centos 8

Step 6: 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
SELinux filesystem relabeling process

Step 7: 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
Log in to centos 8 server

This concludes the steps to reset forgotten root password in CentOS 8, RHEL 8 and its clones like AlmaLinux 8 and Rocky Linux 8.

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. By using this site, we will assume that you're OK with it. Accept Read More