Goglides Dev 🌱

Cover image for How to Reset the Root Password of Linux (CentOS 8)
Roshan Thapa
Roshan Thapa

Posted on

How to Reset the Root Password of Linux (CentOS 8)

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:

:/# chroot /sysroot

You will now be able to change the root password.

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

:/# passwd root

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:

:/# touch /.autorelabel

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

:/# exit

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

:/# reboot

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:

$ sudo passwd root

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.

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.

Top comments (0)