How to reset AlmaLinux / Rocky Linux 8 root password

Have you forgotten your AlmaLinux or Rocky root user password, then here is the step-by-step tutorial to rest the root password using the command terminal.

AlmaLinux / Rocky are the two latest RedHat-based Linux distros meant to use for Servers as well as on Desktops. However, in case after some time you want to log in root user and you couldn’t remember its password then the only way is to recover the root password is by resetting it. Yes, we cannot get our old password at all, instead, we manually have to change it.

What do we learn here:

  • How to change the root password, if lost on AlmaLinux 8 or Rocky?
  • Recovery of the lost root password
  • root user password no longer works, how to reset it?

Steps to reset AlmaLinux / Rocky Linux 8 root user password

1. Go to the boot menu

The first step is to restart your AlmaLinux and when the boot menu appears, press the “e” key on your keyboard. This will open the Grub boot editing interface.  To get an idea see the below-given screenshot.

Edit Boot Menu Alma or Rocky Linux


2. Edit Grub Boot Configuration

As you press the ‘e‘ key on your keyboard the Grub boot configuration will open. There use the arrow keys and just after /swap and before initrd add a line – rd.break enforcing=0 as shown in the below screenshot.

Note: In case there is a line rhg quiet just after /swap then delete that.

Chnage Grub boot configuration

After editing is done, press Ctrl+X to initiate the booting process and Start the Emergency mode scripting Shell. 

Commands to reset AlmaLinux and Rocky Linux root password


3. Mount Filesystem in “read and write” mode

To reset the root password, the first thing we need is the read and write access to the sysroot filesystem. That is by default available only in read-only mode.  Use the below command:

mount -o remount,rw /sysroot

Note: There is a space between the mount and -o and there is also a space between rw and /, which cannot be omitted), and press the Enter key on the keyboard to execute it.


4. Sysroot directory

Chroot is the command that will change the current root directory running process. So, that we can access the file of the Sysroot in a confined environment.

chroot /sysroot


5. Reset AlmaLinux 8 or Rocky password

Finally, everything is set and now we can use the command to reset the available root user’s password.

passwd root


6. Enter a New Password

As we run the above step command, the system will ask us to enter a new password. Just type whatever password your want set for your system’s root user. However, remember as you type nothing will display on the screen. Also, the password should be at least 8 digits, otherwise, it will give a warning that the password is weak. Once you are done press the Enter key.

Commands to reset AlmaLinux and Rocky Linux root password


7. Exit Sysroot

As the new password is set, let’s exit the Sysroot and take the system to its normal Switch_root bash.

Simply type:



8. Make filesystem again read-only

We have changed the filesystem rights above, thus before exiting the system, let’s make it as it was-

mount -o remount,ro /sysroot


9. Exit Session and reboot

To safely reboot the system and leave everything intact exit the current Switch root session and let the system reboot.



10. Login root with a new password

Once you get the login screen of your Rocky or AlmaLinux, log in with your root user and its newly set password. This time you will be able to get admin access to the system.


11. Remove any residue entries and set SELinux enforcing mode

As per the Redhat official guide to reset the password, the developers have mentioned that after resetting the password it is recommended to clean the /etc/shadow that store’s system passwords in an encrypted format to remove any residue entries.

restorecon /etc/shadow

To enable policies of SELinux, run the below command to enforcing them.

setenforce 1


Ending note:

This was the easiest possible way to reset or recover the forgotten root user password on AlmaLinux or Rocky Linux 8, this method will work on both server and desktop/laptop unless you have not set any security policy to disable the user access from editing the grub menu.



Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.