RHCSA9 Exam Series: Resetting the Root Password

RHCSA9 Exam Series: Resetting the Root Password

In this RHCSA9 Exam Series: Resetting the Root Password article, we will review how to change or reset the root password in RHEL9. There’s a slight difference to the way this done as of the 9.0 release and the date of this publication.

Table of Contents

Introduction

Breaking into a RHEL9 machine and changing the root password is almost as straight-forward as before with the exception being, you now have to select the rescue option in the grub menu (bottom of the list). Before we begin, we’re making a few assumptions.

  • You already have a RHEL9 machine installed. If not, this article on installing RHEL7 or CentOS7 on a PC will help you get started. The procedures involved are mostly similar and will assist you with installing RHEL9.
  • You can change the root password on this machine without issue.

Breaking into a RHEL9 machine

You will be required to break into one or more nodes and reset the root password during the RHCSA exam. If you do not know how to do this, you will likely fail as you will not be able to complete any subsequent tasks assigned to that node.
 
Complete the following steps to successfully reset the root password on a RHEL9 machine:
 
  • Reboot your machine and press any key when you arrive at the grub menu to stop the countdown.
  • Next, using your down arrow, highlight the rescue option at the bottom of the list and press the [e] key to enter the edit mode.

Reset the root password in RHEL9 - grub menu

Photo by admingeek from Infotechys

  • Navigate your cursor to the line that begins with the word linux and hit the [end] key to get to the end of that line.
  • Then, type the word rd.break and the press the [ctrl] + [x] keys to proceed with the boot process.

Reset the root password in RHEL9 - grub menu continued

Photo by admingeek from Infotechys

Mounting the root partition in read/write (rw) mode

You will be presented with the option to hit the [Enter] key for maintenance mode or the [Control-D] to proceed with booting into rescue mode.

Press the [Enter] key for the maintenance option.

				
					Press Enter for maintenance
(or press Control-D to continue):
sh-5.1#
				
			

Enter the following command (below) to mount /sysroot partition in read/write mode. Then, press the [Enter] key to continue.

				
					sh-5.1# mount -o remount,rw /sysroot
				
			

Now enter the chroot command (below) to enable the password change and hit the [Enter] key to continue.

				
					sh-5.1# chroot /sysroot
				
			

Changing the root password

We can now proceed with changing the root password by simply entering the passwd command.

				
					sh-5.1# passwd
Changing password for user root.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
sh-5.1#
				
			

Updating Selinux Context

As a result of changing the root password, selinux is set to the incorrect context. Therefore, create the following hidden file under the root directory (below) to ensure the selinux subsystem detects and relabels all files to the correct context.

				
					sh-5.1# touch /.autorelabel
sh-5.1# exit
exit
sh-5.1# exit
				
			

Enter the exit command and press [Enter] twice to escape maintenance mode and proceed with the boot process.

Selinux Context and Relabeling

Photo by admingeek from Infotechys

Conclusion

The boot process will finally arrive at a login prompt where you can test your new root password. If you can log on successfully, congratulations! You have successfully broken into and reset the root password on a RHEL9 machine!

Was this article helpful to you? If so, leave us a comment. We’d love to hear from you!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *