RHCSA Practical Lab Series β Resetting the Root Password
π 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:
- Reboot the system and press
e
when the GRUB menu appears. - Locate the line starting with
linux
orlinux16
. - 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 forroot
.
β 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!