Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  How-Tos  >  Steps to Reset Forgotten Password in Rocky Linux/Alma Linux
Top Scroll

Steps to Reset Forgotten Password in Rocky Linux/Alma Linux

 3 min

If you have forgotten your AlmaLinux or Rocky root user password, here is a step-by-step guide to reset the root password using the command terminal.

Usually, this can happen due to various reasons. First reason can be that your last login was through the root user a while ago. Another reason can be that you have a very difficult password that needs a password manager for storing securely.

AlmaLinux/Rocky are the newest RedHat-based Linux distros. However, if in case, after some time, you need to login in root user and you forget the password, then the only way to recover it is by resetting it.

This article will explain the steps to reset the forgotten password in Linux/Alma Linux.

Step 1: Editing the Kernel Parameters

First, you need to reboot the system. On the first entry of the grub menu, press “e” on the keyboard to access the GRUB editor.

Editing the Kernel Parameters

rd.break enforcing=0

rd.break enforcing

If you need to gain access to the emergency mode, press Ctrl+x.

Step 2: Resetting the Root Password

To reset the root password, you need access to the /sysroot directory with read and write permissions. To mount the/sysroot directory with the read and write permissions, enter the command given below:

# mount -o rw,remount /sysroot

Note: Make sure to take note of the space between the mount and -o and between the remount and /.

In the next step, change the directory environment to /sysroot.

# chroot /sysroot


If you want to reset the root password, type the command below. You will have to provide a new password and reset it later.

# passwd root

passwd root

Step 3: Setting the SElinux Context

# touch  /.autorelabel

This command creates a hidden file called .autorelabel in the root directory. During the reboot, SELinux detects the file and re-labelles all the files on the system with the correct SELinux contexts. This process takes some time in the system with ample disk space.


Once you have completed the process of autorelabel, exit the /sysroot environment using the command given below:

$ exit

Again, run the exit command to leave, switch the root session, and reboot the system.

$  exit

Once you have rebooted the system successfully, you can login and switch to the root user easily.


This is one of the simplest ways to reset the forgotten root user password on Alma Linux or Rocky Linux. And that’s it!

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
Claim the discount before it’s too late. Use the coupon code:
Note: Copy the coupon code and apply it on checkout.