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.
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.
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.
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.
After pressing the Ctrl+x It will take to a Console as shown on the snapshot below.
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.
So let’s mount /sysroot with rw ( Read / Write ) Permission using the below command.
As we can see on the snapshot below now /sysroot is with rw ( Read / Write ) Permission.
Now here type command chroot /sysroot/ to treat the directory as root and will redirect you to a shell prompt as shown below.
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.
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.
Then run exit command to come out from Shell Prompt and then run reboot command to restart the system.
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.