How to Change and Reset Forgotten Root Password in RHEL 9

While installation of RHEL 9, the installer recommends we choose a complex password and while making the password complex enough, the chances of forgetting our password are quite high. And things get even more complex when your user is not even added to the wheel group (which allows a normal user to elevate root privileges for a small amount of time).

This tutorial will guide you on how you can change your forgotten root password in 3 scenarios and we are quite sure that you’ll be able to recover your forgotten password at the end of this guide.

Method 1: Changing Root Password in RHEL 9

So if you are a root user and want to change your existing root password, you can accomplish this task with a single command.

# passwd
Change Root Password in RHEL 9
Change Root Password in RHEL 9

And it will ask you to enter your new root password. For confirmation, it will ask you again for entering the new password and it will throw a message saying “all authentication tokens updated successfully”.

Method 2: Changing Root Password as Sudo User

For the majority, this will be the case where the user is added to the wheel group and want to change the root password. Thankfully, you can change your root password even if you don’t know the current one.

To change your root password as a wheel group user, utilize the given command:

$ sudo passwd root
Sudo User Change Root Password
Sudo User Change Root Password

First, you’ll be asked to enter your user password and after that, you’ll be allowed to change your root password by entering it twice and for confirmation.

Method 3: Changing Forgotten Root Password in RHEL 9

This method is for those who are not root users or their local user is not added to the Wheel group and still wants to change or reset their forgotten root password.

This is the most complex method and while using this method, make sure you read commands twice before applying them as we will be dealing with GRUB.

Step 1: Enter GRUB Edit Mode

To enter GRUB edit mode, first, we have to reboot our system. When you see GRUB 2 screen, press the 'e' key to interrupt the boot process.

RHEL Grub Boot Menu
RHEL Grub Boot Menu

Once you press 'e', it will show us kernel boot parameters.

Kernel Boot Parameters
Kernel Boot Parameters

Step 2: Edit Kernel Boot Parameters

Once you enter Kernel boot parameters, go to the end of the line which starts with linux. The easiest way to do that is first to go to the line that starts with linux and press CTRL + e to jump to the end of the line.

View Kernel Boot Parameters
View Kernel Boot Parameters

Once you are at the end of the line, add rd.break and press CTRL + x to start the system with changed parameters.

Edit Kernel Boot Parameters
Edit Kernel Boot Parameters

Step 3: Reset Forgotten Root Password

You will be given an emergency mode prompt. From here, we will be mounting our drives, entering into chroot environment, and changing our root password. Press Enter and the sh-5.1 prompt will appear for further process.

RHEL Emergency Mode Prompt
RHEL Emergency Mode Prompt

By default, the file system is mounted as read-only under /sysroot directory. By using the given commands, we will be remounting them to make them writable and change our password.

# mount -o remount,rw /sysroot

After mounting drives, let’s enter into chroot environment which will allow us to make changes directly to system files.

# chroot /sysroot

Finally, we can change our root password by utilizing the given command:

# passwd
Change Forgotten Root Password in RHEL 9
Change Forgotten Root Password in RHEL 9

After changing the password, let’s enable SELinux relabeling process on the next system boot.

# touch /.autorelabel

Important: We are not running any scripts here, so make sure you use /.autorelabel correctly.

After changing the password and relabeling, let’s exit chroot environment by the given command:

# exit

Similarly, to exit from the sh-5.1 prompt, we will be using the given command:

# exit

Step 4: Verify Root Password

To verify whether we have successfully changed our root password or not, log in as a normal user and open the terminal emulator and run an interactive shell as root, utilize the given command:
$ su

Enter the newly configured root password. To print the username associated with a current user ID, we will be using the given command:

# whoami
Check Root User Login
Check Root User Login

And it will return as “root”.

This guide has shown 3 methods by which you can change your forgotten root password in RHEL 9. But if you still have any doubts, feel free to mention them in the comments.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Sagar Sharma
I'm a software engineer trying my best to bring open-source software to a general audience. Being a Linux author solves my purpose.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

3 Comments

Leave a Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.