How to Reset Forgotten Root Password in Rhel/Centos 7

In this article, we are going to learn how to reset forgotten root password in RHEL 7 / CentOS 7. In my previous post I have explained the same topic but for CentOS 6. Then I got a comment from one of my subscribers to write an article for RHEL 7.

How to Reset Forgotten Root Password in Rhel/Centos 7
How to Reset Forgotten Root Password in Rhel/Centos 7

Follow the steps below to reset forgotten root password:

Step: 1 Edit the GRUB

Start the System and press any key to interrupt the normal boot process, then you will able to see the screen as shown below, Here Select the GRUB option ( Highlighted in Blue Color on Snapshot below ) and press “e” to edit it.

You can also see the message showing by the system on the lower portion of the screen as shown on the snapshot below.

Note: You can select the menu by using the UP and DOWN arrow.

How to Reset Forgotten Root Password in Rhel/Centos 7
Edit Grub

Step: 2 Make Changes in Kernel

After the edit, the GRUB looks for the kernel line starting with linux16 as highlighted below on the snapshot below.

Note: The below screen is Scrollable, You can use the UP and DOWN arrow to scroll the Screen.

How to Reset Forgotten Root Password in Rhel/Centos 7
Edit the Kernel Argument

Here go to the end of the line and just after the word UTF-8 write rd.break ( Highlighted in Blue Color on the Snapshot below ) and then Press Ctrl+x ( Highlighted in Yellow Color on the Snapshot below) to go for further process. Follow the Snapshot below.

How to Reset Forgotten Root Password in Rhel/Centos 7
Add rd.break at the end of the Kernel

After pressing the Ctrl+x It will take to a Console as shown on the snapshot below.

How to Reset Forgotten Root Password in Rhel/Centos 7
Shell Prompt

Step : 3 Give Write Permission to /sysroot

Here we need to mount the /sysroot with rw ( Read/Write ) permission to reset the root password as by default the /sysroot would be in ro ( Read-Only ) Permission mode.

We can check that by using the mount command, Follow the snapshot below.

How to Reset Forgotten Root Password in Rhel/Centos 7
Check the Permission of Sysroot

So let’s mount /sysroot with rw ( Read / Write ) Permission using the below command.

How to Reset Forgotten Root Password in Rhel/Centos 7
Give write permission to Sysroot

As we can see on the snapshot below now /sysroot is with rw ( Read / Write ) Permission.

How to Reset Forgotten Root Password in Rhel/Centos 7
Check the Sysroot Permission

Now here type command chroot /sysroot/ to treat the directory as root and will redirect you to a shell prompt as shown below.

sh-4.2#

Step: 4 Reset the root Password

So now we are with a Shell Prompt. Here we can reset the Linux root password using passwd command as shown on the snapshot below.

How to Reset Forgotten Root Password in Rhel/Centos 7
Set root Password

As we can see on the snapshot above root password updated Successfully now run the below command to Relabel the filesystem for SElinux automatically.

Note: After making any changes it is Recommended to relabel the file system to make all the applications start with a proper labels.

How to Reset Forgotten Root Password in Rhel/Centos 7
Relabel the File System

Then run exit command to come out from Shell Prompt and then run reboot command to restart the system.

How to Reset Forgotten Root Password in Rhel/Centos 7
Reboot the System

Also Read – How To Protect Grub2 Bootloader With Password In Rhel/Centos

Now you can use the new password for user root to log in to the system. That’s all, In this article, we have explained How to Reset Forgotten Root Password in Rhel/Centos 7. I hope you enjoy this article. If you like this article, then just share it. If you have any questions about this article, please comment.

Share this:
WhatsApp Channel Join Now
Telegram Channel Join Now
Instagram Channel Join Now

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.