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.
In the next screen, you will see the Kernel boot parameters. Find the kernel parameter ro:
…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...".
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/
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.
After updating the root password, enter the following command to enable SELinux relabeling on reboot :
touch /.autorelabel
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.
Once the filesystem relabeling is completed, you can log in to your CentOS 8 server with new root password:
Suggested read:
Hope this helps.
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Reddit | Facebook | Twitter | LinkedIn | RSS feeds
Have a Good day!!
1 comment
Hi,
Very nice and useful article.
Thanks a lot