CentOS 8 is widely used by the users to set up various server environments, thus a strong password is needed. However, somehow, if you forget the root password then the only way to get access to it is by resetting.
In this tutorial, we will show you the steps to reset the CentOS 8 Linux root password that has been forgotten due to any reason. So let’s start the steps to retrieve or change the password?
What we learn here:
- how to change the root password, if lost?
- Recovery of the lost root password
- root password no longer works, how to reset it?
- Steps to reset CentOS 8 root user password
- 1. Go to the boot menu
- 2. Drop CentOS 8 boot to Shell
- 3. Start the Emergency mode scripting Shell
- 4. Mount Filesystem in “read and write” mode
- 5. Chroot /Sysroot
- 6. Reset password
- 7. Enter New Password
- 8. Return back to Switch root
- 9. Make sysroot again read-only
- 10. Exit Session and reboot
- 11. Login root with a new password
- 12. Clean up and set SELinux enforcing mode
- Verdict: RedHat 8 password change
Steps to reset CentOS 8 root user password
This tutorial is also applicable to previous versions of this Linux operating system that are CentOS 7 and CentOS 6. Moreover, we are not using SELinux autorelabel which sometimes causes problems.
The first step is to start the CentOS 8 and when the boot menu appears, press the “e” key on your keyboard. This will open the Grub 2 boot editing interface. To get an idea see the below-given screenshot.
2. Drop CentOS 8 boot to Shell
In the Grub boot configuration, use the arrow key and replace the line
rhg quiet with
You can see how we have done, in the same way, add the mentioned string.
3. Start the Emergency mode scripting Shell
After the addition of the syntax given in the previous step, boot the system by pressing Ctrl+X. This will boot CentOS 8 in the shell rather initiating the system init daemon.
4. Mount Filesystem in “read and write” mode
To reset the root password of this Linux, the first thing we need is the read and write access to the sysroot filesystem. That is by default available only in read-only mode. Use the below command:
mount -o remount,rw / sysroot
Note: There is a space between the mount and -o and there is also a space between rw and /, which cannot be omitted), and press Enter key on the keyboard to execute it.
5. Chroot /Sysroot
Chroot is the command that will change the current root directory running process. So, that we can access the file of the Sysroot in a confined environment.
6. Reset password
Finally, everything is set and the command we need to reset the available root user password.
7. Enter New Password
Now, enter the new password at the blinking position of the cursor (the password is not displayed when you enter it, just like there is no response). But remember that the password you entered is correct. Yes, the password should be at least 8 digits, otherwise, it will give a warning that the password is weak. Once you are done press Enter on the keyboard after completion.
8. Return back to Switch root
As we have recovered the lost password problem, thus not get back to Switch root and make the system to its normal state.
9. Make sysroot again read-only
As we have manually change the mode of the default file system, thus make it as it was. Here is the command:
mount -o remount,ro /sysroot
10. Exit Session and reboot
To safely reboot the system and leave everything intact exit the current Switch root session and let the system reboot.
11. Login root with a new password
Next, on login screen enter username root and password that you have set and click “Login” when finished.
12. Clean up and set SELinux enforcing mode
Just to convey a proper way of doing the things as official website RHEL recommends, clean the /etc/shadow that stores system password in an encrypted format to remove any residue entries.
To enable polices of SELinux, run below command to enforcing it.
Verdict: RedHat 8 password change
So, this was the safest way we can use to recover our system that root user password we forgot on RHEL or CentOS.