Reset Root Password on AlmaLinux 9 | Quick and Easy

Posted on

Reset Root Password on AlmaLinux 9 | Quick and Easy

In this guide, we intend to teach you How To Reset Root Password on AlmaLinux 9. In Linux, root privileges (or root access) refer to a user account that has full access to all files, applications, and system functions.

Most basic Linux user accounts run with limited privileges. This keeps users from making mistakes or accidentally exposing the system to vulnerabilities.

To use protected operating system features, a Linux user has to temporarily elevate their privileges using a command like sudo. The sudo command tells the system to run a command as a superuser, or root user. When you run a function using sudo, you’ll usually have to enter your password.

If you forget your root password, you can easily follow the steps below on the Orcacore website to recover it on AlmaLinux 9.

In this guide, we will show you how to Recover Lost Root Password from the Grub Menu on AlmaLinux 9. Follow the steps below to complete this guide.

First, you need to restart your system, and while doing that, press and hold the Shift key on your Keyboard. This will drop you into the Grub menu of AlmaLinux 9.

Next, you need to press the ‘e’ key on your keyboard. This will let you edit the Grub’s boot prompt. Don’t touch or delete anything here. Once you have the editor, move to the next step.

At this point, use your arrow key and move to the end of the line starting with “Linux”. After the root ro line, type rw init=/bin/bash.

rw init=/bin/bash
Grub Menu AlmaLinux 9

After adding the syntax, boot your system with this configuration. To do this, you can use Ctrl+X or F10.

2. Root Shell Access on AlmaLinux 9

At this point, without providing any password you will have an AlmaLinux 9’s shell with root access.

First, let’s check whether your user has read and write access to the file system where the OS has been installed.

To do this, run the following command:

mount | grep -w /

If you see (rw,realtime) in your output, it means you have real-time read and write access to the file system.

3. Change Root Password on AlmaLinux 9

Now you can simply change your root password on AlmaLinux 9 with the following command:

passwd

The system will prompt you to add a new password two times.

To change the password of some other user than root, we have to mention the username of the same. The syntax is like the following command:

passwd <mark>username</mark>

When you are done resetting your Linux password, restart your system to log in with the changed password. For rebooting, run the command below:

exec /sbin/init

After that, hit the Enter key.

From here, you can log in and access your system with the newly set root password.

Conclusion

At this point, you have learned to Reset or Recover the Lost or Forgotten Root Password on AlmaLinux 9 from the Grub Menu. Hope you enjoy it. Please subscribe to us on Facebook and YouTube.

You may be like these articles:

How To Disable SELinux on AlmaLinux

Disable NetworkManager on AlmaLinux 8

Check Installed Linux Kernel in Command Line

FAQs

How do I access the GRUB menu on AlmaLinux 9?

To access the GRUB menu, restart your system and press “Esc” or “Shift” repeatedly during boot until the GRUB menu appears.

What if I cannot access the GRUB menu AlmaLinux 9?

If GRUB is password-protected, you may need BIOS/UEFI access to reset it.

Will this method work for non-root users?

No, this method is specifically for resetting the root password.

Alternative Methods to Reset Root Password on AlmaLinux 9

While the method described above is effective, there are alternative approaches to reset root password on AlmaLinux 9 if you encounter difficulties or prefer a different technique. Here are two additional methods:

1. Using a Rescue Environment (AlmaLinux Installation Media)

This method involves booting your AlmaLinux 9 system from a rescue environment, typically using the installation media (DVD or USB drive). This allows you to access the system’s files and reset the root password without needing the GRUB menu.

Steps:

  1. Boot from Installation Media: Insert your AlmaLinux 9 installation media (DVD or USB) and configure your BIOS/UEFI to boot from it.

  2. Enter Rescue Mode: Once the installation media boots, you’ll typically be presented with a menu. Choose the "Troubleshooting" option, and then select "Rescue a AlmaLinux system."

  3. Mount the File System: The rescue environment will attempt to find your existing AlmaLinux installation. It will prompt you to mount the file system. Choose the option to mount it in read-write mode.

  4. Chroot into the System: After mounting the file system, you need to change the root directory to your installed system. This is done using the chroot command:

    chroot /mnt/sysimage

    This command effectively makes your existing AlmaLinux system the "root" directory for the current shell.

  5. Reset the Root Password: Now that you’re chrooted into your system, you can reset the root password using the passwd command:

    passwd root

    Enter the new password when prompted.

  6. Update SELinux Contexts (Important): Because you’ve modified a system file outside of the normal boot process, it’s crucial to update the SELinux contexts to prevent potential security issues. This is done with the following command:

    touch /.autorelabel

    This command creates a file named .autorelabel at the root of your file system. On the next reboot, SELinux will automatically relabel all files, ensuring proper security contexts.

  7. Exit Chroot and Reboot: Exit the chroot environment by typing exit. Then, unmount the file system and reboot your system:

    exit
    umount /mnt/sysimage
    reboot
  8. Login with the New Password: After the reboot, you should be able to log in as root with the new password you set. The system will take a while to boot because of the SELinux relabeling process.

This method is useful when you can’t access the GRUB menu or if you prefer a more controlled environment for resetting the password. This is a good way to reset root password on AlmaLinux 9.

2. Using systemd.unit=rescue.target Kernel Parameter

Another method involves using a kernel parameter to boot directly into rescue mode, bypassing the need for installation media. This is a quicker alternative if you can access the GRUB menu.

Steps:

  1. Access GRUB Menu: Restart your system and access the GRUB menu as described in the original article (holding Shift during boot).

  2. Edit Boot Entry: Press ‘e’ to edit the boot entry.

  3. Add Kernel Parameter: Find the line starting with "linux" or "linuxefi". At the end of the line, add the following parameter:

    systemd.unit=rescue.target

    The line should look similar to this (the exact contents before systemd.unit=rescue.target will vary):

    linux   /boot/vmlinuz-5.14.0-284.11.1.el9_2.x86_64 root=UUID=... ro crashkernel=auto resume=UUID=... rhgb quiet systemd.unit=rescue.target
  4. Boot the System: Press Ctrl+X or F10 to boot the system with the modified entry.

  5. Login as Root: The system will boot into rescue mode, prompting you to log in as root. You may or may not need a password at this point. If a password is required and you don’t know it, continue with the next steps.

  6. Remount Root File System: The root file system is likely mounted as read-only. Remount it in read-write mode:

    mount -o remount,rw /
  7. Reset Root Password: Now you can reset the root password using the passwd command:

    passwd root

    Enter the new password when prompted.

  8. Reboot the System: Reboot the system:

    reboot

    You can now log in with your new root password.

This method avoids the need for external media and provides a relatively quick way to access a root shell for password reset. This technique will certainly reset root password on AlmaLinux 9.

Both of these alternative methods offer ways to reset root password on AlmaLinux 9, providing flexibility depending on your situation and access to resources. Remember to always update SELinux contexts after modifying system files outside of the normal boot process to maintain system security.