RHCSA Practical Lab Series – Resetting the Root Password

Expertise in Cloud, Networking & DevOps
Photo by Robs / Unsplash

πŸ” Lab 16: Resetting the Root Password in RHEL 9

πŸ“Œ Objective

In this lab, you will:

βœ” Reset the root password on a RHEL 9 system
βœ” Use emergency mode to gain access
βœ” Ensure that SELinux relabeling is triggered to prevent login issues


πŸ“Œ Step 1: Boot into Emergency Mode

πŸ”Ή Start the system and interrupt the boot process:

  1. Reboot the system and press e when the GRUB menu appears.
  2. Locate the line starting with linux or linux16.
  3. Press Ctrl+X to boot into emergency mode.

Modify the boot parameters by appending the following at the end of the line:

rd.break

βœ… You should now have access to a minimal rescue shell.


πŸ“Œ Step 2: Remount the Filesystem in Read-Write Mode

πŸ”Ή By default, the root filesystem is mounted as read-only. Remount it as read-write:

switch_root:/# mount -o remount,rw /sysroot

βœ… Verify the change:

switch_root:/# mount | grep sysroot

πŸ”Ή Expected Output:

/dev/mapper/rhel-root on /sysroot type xfs (rw,relatime)

πŸ“Œ Step 3: Access the System and Reset the Root Password

πŸ”Ή Change the root directory to /sysroot:

switch_root:/# chroot /sysroot

πŸ”Ή Reset the root password to SecurePass123:

sh-4.4# echo SecurePass123 | passwd --stdin root

πŸ“Œ Explanation:

  • chroot /sysroot β†’ Switches into the installed system environment.
  • passwd --stdin root β†’ Sets the new password for root.

βœ… If successful, you will see:

passwd: all authentication tokens updated successfully.

πŸ“Œ Step 4: Trigger SELinux Relabeling

πŸ”Ή Create a file to ensure SELinux relabeling occurs on reboot:

sh-4.4# touch /.autorelabel

πŸ“Œ Why?

  • Without relabeling, you might face login failures due to incorrect SELinux contexts.

βœ… If the command executes without errors, proceed to the final step.


πŸ“Œ Step 5: Reboot the System and Verify

πŸ”Ή Exit the chroot environment and reboot the system:

sh-4.4# sync
sh-4.4# exit
switch_root:/# exit

πŸ”Ή After the system reboots, log in as root with the new password:

login: root
Password: SecurePass123

βœ… If login is successful, the password reset was successful!


πŸ“Œ Step 6: Confirm SELinux Relabeling (Optional)

πŸ”Ή Check if SELinux relabeling was performed:

[root@node2 ~]# ls -Z /

πŸ“Œ Expected Output:

drwxr-xr-x. root root system_u:object_r:root_t:s0 /

βœ… If SELinux labels are correct, the reset process is complete.


βœ… Final Summary

βœ” Booted into emergency mode and remounted the filesystem
βœ” Used chroot to reset the root password
βœ” Ensured SELinux relabeling to avoid login failures
βœ” Successfully logged in with the new password


πŸ“Œ Next Lab: Setting Up Default Package Repositories in RHEL 9

πŸ“© Subscribe for more RHCSA exam labs and hands-on tutorials!

Read more