In this article, we will learn how to reset the root password on CentOS 8. A root account is a unique user account that grants certain privileges to the user.
Resetting Forgotten Root Password
If you have forgotten your password and after trying a lot to remember your old password, you are still unable to get that. Do not worry; we can reset the root password from the GRUB Boot Menu.
For resetting the root password, first, reboot your computer.
When the system restarts, press the “ESC” key immediately to interrupt the boot process.
Select the kernel from the GRUB/Boot menu you want to boot into by pressing the arrow keys.
Pressing ‘e’ from your keyboard will open the editing menu.
In the editing menu, locate the “ro” kernel parameter and replace it with “rw,” and add an additional parameter “init=/sysroot/bin/sh”:
Press Ctrl + X to enter into the single-user mode once you are done with the previous step.
Now run the “chroot /sysroot” command to convert the root file system in read and write mode:
You will now be able to change the root password.
To set a new password for root, input the command:
You will then be asked to input a new password and then confirm it. It is best to use a unique, complex, and complicated password that is easy to remember.
Now the next step is to initiate SELinux relabelling. To start the relabelling of SELinux, use the following command:
After relabeling, Use the following command to save and apply the changes:
Once everything is changed and saved, reboot your computer by using the “reboot” command:
You may need to wait a few minutes to let the SELinux relabelling process complete.
Upon completion, the system will reboot, and the login screen will appear.
You will have to use the new password; next time you log in as the root user.
Resetting Root password from Terminal
If you need to reset your root password and know the current password, there is no need to do anything complex. Just fire up your CentOS 8 terminal and type the command given below:
If you are logged in as a root user, you will be asked to input the new password and then confirm the new password.
If you are logged in as a normal user with Sudo privileges, you will be asked to input your current password, the new password, and then confirm the new password.
Please do not select common words as your password.
Once you have successfully reset your root password, you have to log in with this new set password as a root user.
In this article, we’ve learned how to reset a root password that is forgotten. Moreover, we also learned to set up a new root password if you remember your current password.
We discussed the importance of setting a unique password and what kind of passwords we can use. We also touched a bit on the topic of what is a root user.