What can you do when you have forgotten the root password of a CentOS 8 computer? In this tutorial, you are going to learn how to reset the root password. There are several methods to do this task. Here we will explain the easiest way.
First of all, reboot your computer and press the
ESC key to interrupt the normal boot. You will see the list of available kernel versions on your computer. The latest kernel version is at the top of the list. [Figure 1.0]
Select the kernel version and press the
‘e’ key to edit the chosen entry. Use up, down arrow keys to select the line started with Linux word. [Figure 2.0]
Edit that line and replace the
ro (read-only ) with “
rd.break” string as below. [Figure 3.0]
It will break the boot process before the control handed from the initramfs to the actual file system.
Change the configuration carefully and then press
ctrl + x to start the boot with changes.
You will be directed to the root shell with the root file system for the actual system mounted as read-only on /sysroot.
Mount the /sysroot as read-write. Use the following command for the remount.
mount -o remount,rw /sysroot
Then execute the following command.
Now you can change the root password.
Now execute the following command to relabel all the unlabeled files with SELinux security contexts.
You can see the relabeling process going on.
Now you have completed all the required steps to change the root password. Type exit two times or just press Ctrl + d keys twice to reboot.
It will take a few minutes to finish relabeling the files.
After reboot, you can use the new root password to log into the file system.
In this tutorial, you learn how to change a root password from the single-user mode in CentOS 8.
Please comments on any doubts or suggestions.