Hackers have become a lot more sophisticated in recent times, which forces users to come up with strong, unique, and complex passwords. The downside of setting such passwords is that they are not easy to remember, and you can easily forget them. You may also forget your password if you haven’t logged in in a long time.

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.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/1-7.png" data-lazy- height="396" src="data:image/svg xml,” width=”717″>

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.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/2-7.png" data-lazy- height="389" src="data:image/svg xml,” width=”710″>

Pressing ‘e’ from your keyboard will open the editing menu.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/3-7.png" data-lazy- height="397" src="data:image/svg xml,” width=”717″>

In the editing menu, locate the “ro” kernel parameter and replace it with “rw,” and add an additional parameter “init=/sysroot/bin/sh”:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/4-7.png" data-lazy- height="58" src="data:image/svg xml,” width=”716″>

Press Ctrl X to enter into the single-user mode once you are done with the previous step.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/5-6.png" data-lazy- height="458" src="data:image/svg xml,” width=”668″>

Now run the “chroot /sysroot” command to convert the root file system in read and write mode:

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/6-5.png" height="63" src="data:image/svg xml,” width=”186″>

You will now be able to change the root password.

To set a new password for root, input the command:

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/7-5.png" height="56" src="data:image/svg xml,” width=”286″>

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.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/8-5.png" data-lazy- height="99" src="data:image/svg xml,” width=”452″>

Now the next step is to initiate SELinux relabelling. To start the relabelling of SELinux, use the following command:

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/9-5.png" height="39" src="data:image/svg xml,” width=”209″>

After relabeling, Use the following command to save and apply the changes:

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/10-4.png" height="52" src="data:image/svg xml,” width=”97″>

Once everything is changed and saved, reboot your computer by using the “reboot” command:

<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/11-4.png" height="36" src="data:image/svg xml,” width=”99″>

You may need to wait a few minutes to let the SELinux relabelling process complete.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/12-3.png" data-lazy- height="260" src="data:image/svg xml,” width=”802″>

Upon completion, the system will reboot, and the login screen will appear.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/13-1.png" data-lazy- height="220" src="data:image/svg xml,” width=”398″>

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.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/14-1.png" data-lazy- height="115" src="data:image/svg xml,” width=”509″>

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.

Conclusion

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.

About the author

<img alt="" data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2021/07/echo/7011409B3A384F43A8417D1DAC68D179-150×150.jpg" height="112" src="data:image/svg xml,” width=”112″>

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.