Steps to Reset Forgotten Password in Rocky Linux/Alma Linux

Posted on

If you’ve forgotten the root user password for your AlmaLinux or Rocky Linux system, this guide provides a step-by-step procedure to reset it using the command terminal.

Forgetting the root password is a common issue that can happen for several reasons. You might not have logged in as root for a long time, or you might have chosen a complex password that requires a password manager to store it securely.

AlmaLinux and Rocky Linux are relatively new Red Hat-based distributions. If you need to access your system as the root user after a period of time and find that you have forgotten the password, resetting it is the only recovery option.

This article will walk you through the necessary steps to reset a forgotten root password on both AlmaLinux and Rocky Linux.

Step 1: Modifying Kernel Parameters in GRUB

Begin by rebooting your system. When the GRUB menu appears, select the first entry and press the “e” key to enter the GRUB editor.


Editing the Kernel Parameters

Once in the GRUB editor, scroll down using the arrow keys until you find the line starting with “Linux”. Use the right arrow key to go to the end of the line, and append the following directive:

rd.break enforcing=0


rd.break enforcing

Press Ctrl+x to boot the system with these modified parameters, which will drop you into emergency mode.

Step 2: Resetting the Root Password

To reset the root password, you need read and write access to the /sysroot directory. To mount this directory with those permissions, use the following command:

# mount -o rw,remount /sysroot

Note: Be sure to include a space between “mount” and “-o”, and also between “remount” and “/”.

Next, change the root directory to /sysroot using the chroot command:

# chroot /sysroot


sysroot

Now, execute the passwd command to reset the root password. Follow the prompts to enter your new password.

# passwd root


passwd root

Step 3: Setting the SELinux Context

Create a hidden file named .autorelabel in the root directory. This will force SELinux to re-label all files on your system with the correct contexts upon reboot.

# touch  /.autorelabel

Note that this process may take considerable time.


autorelabel

Once the .autorelabel file is created, exit the /sysroot environment using the following command:

# exit

Run the exit command again to leave the emergency mode and reboot the system.

#  exit

After the reboot, you should be able to log in as root with your new password.

Conclusion

This is a straightforward procedure for resetting a lost root password on AlmaLinux or Rocky Linux. You are all set!

Leave a Reply

Your email address will not be published. Required fields are marked *