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.
Step 2: In the next screen, you will see the Kernel boot parameters. Find the kernel parameter
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 "
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.
Step 4: Now, change the root user password using command:
Enter the password twice. I recommend you to use any strong password that contains numbers and special characters.
Step 5: After updating the root password, enter the following command to enable SELinux relabeling on reboot :
Step 6: Finally, type the following commands to apply the changes and reboot the CentOS server to normal mode:
Wait for SELinux relabeling process to complete. It will take some time depending upon the filesystem size and speed of your hard drive.
Step 7: Once the filesystem relabeling is completed, you can log in to your CentOS 8 server with new root password:
This concludes the steps to reset forgotten root password in CentOS 8, RHEL 8 and its clones like AlmaLinux 8 and Rocky Linux 8.