Red Hat

How to Reset Root Password on Rocky Linux

How to Reset Root Password on Rocky Linux

If you need to log in as a root user on your Rocky Linux system after some time and can’t remember its password, the only method to recover is to reset it.

In this article, we will guide you on how to reset your root password on Rocky Linux 8 from the GRUB menu. The GRUB menu is a boot loader and software that loads and transfers control to an operating system, such as Linux, when a computer is turned on.

So, let’s dive into this step-by-step tutorial of resetting the root password

Step 1: Reboot Rocky Linux

First, restart Rocky Linux 8 and press ‘e ‘ on the keyboard as soon as the boot menu appears. This will display the Grub editing interface.

Step 2: Edit Boot Grub Configuration

Next, we need to edit the Grub boot configuration interface. Use arrow keys to navigate the interface. Locate the line beginning with linux and scroll to the end of the line using the arrow forward key.

Then append the line rd.break enforcing=0 .

Thereafter, initiate the booting process using Ctrl+X and start the Emergency mode scripting shell.

Step 3: Mount Filesystem in “read and write” mode

In order to reset the root password on Rocky Linux, we first need read and write access to the sysroot filesystem. Run the following command to mount the filesystem in ‘read’ and ‘write ‘ mode:

$ mount -o remount,rw /sysroot

Next, navigate the directory to the sysroot directory using the command below:

$ chroot /sysroot

Step 4: Reset password

Finally, everything is in place, and we can now change the password of the available root user. Run the command shown:

$ passwd root

The system will prompt you for a new password. Ensure to set a strong password with at least 8 characters, otherwise, you will be warned that the password is weak. If everything is correct, the password will be updated successfully. Press the Enter key to proceed. Next, exit the Sysroot directory using the exit command.

To reset the root password, we changed the file system rights to read and write. We need to set it back to read only. Therefore, execute the command:

$ mount -o remount,ro /sysroot

Step 5: Exit session and reboot

Next, exit the switch root session and let your system restart.

$ exit

You can now log in to your root user with the new password.

Step 6: Set SELinux enforcing modes

According to the Redhat official guide of resetting system passwords, it is recommended to delete any residue entries from the /etc/shadow file that stores system passwords. So, once you have logged in execute the following command:

$ restorecon /etc/shadow

Next, enable policies of SELinux as shown:

$ setenforce 1


Resetting the root password on Rocky Linux is a simple and straightforward process as demonstrated in this guide.

Similar Posts