Article overview

Help article

Resetting your root password in CentOS Stream, AlmaLinux or Rocky Linux

Over time you may forget your root password, but luckily there usually is a solution. In this tutorial, we will show you how to reset your root password in CentOS 8CentOS Stream, AlmaLinux and Rocky Linux. For CentOS 7,  see this tutorial.

Do you still have your root password, but have you lost another user's password? Then use the following command as root user to change the password::

passwd username

 

Step 1

To reset your root password, switch to the 'single user mode' of your VPS. To do this, restart your VPS and press the 'e' key on your keyboard as soon as you see the screen below.

Please note: use the VPS console in the control panel and press ctrl-alt-del and don’t press restart. The screen below will then remain on the screen for a longer period of time.

centos 8 reboot menu


 

Step 2

You will now see a lot of text on your screen. These determine the boot parameters of your VPS. Use the arrows on your keyboard to navigate down and search for 'ro'.

centos 8 rescue boot read only

Edit this part to 'rw init=/sysroot/bin/bash' (without parentheses) so that it looks like this:

centos 8 rescue mode boot read write


 

Step 3

Press ctrl + x to start your VPS with the custom boot parameters. You are now in rescue mode.

Then mount your root file system with read write properties via the command:

chroot /sysroot/

 

Step 4

You can now reset your root password with the command:

passwd root
touch /.autorelabel
  • passwd root resets the root password
  • touch /.autorelabel adds a hidden file called autorelabel in the root directory. This file tells SELinux to relabel the entire filesystem. Without this additional step, your password reset won’t work. More information about labeling in SELinux can be found here.

 

Step 5

Finally, exit your mounted root file system and reboot your VPS with the commands:

exit
reboot

You can now login with your new root password!


 

That brings us to the end of this tutorial to resetting your root password in CentOS 8, CentOS Stream, AlmaLinux and Rocky Linux.

Should you have any questions left regarding this article, do not hesitate to contact our support department. You can reach them via the ‘Contact Us’ button at the bottom of this page.

If you want to discuss this article with other users, please leave a message under 'Comments'.

Has this article been helpful?

Create an account or log in to leave a rating.

Comments

Create an account or log in to be able to leave a comment.