How to Reset Forgotten Root Password of RHEL7 / CentOS7

How to Reset Forgotten Root Password of RHEL7 / CentOS7

This post will help you with How to Reset Root Password of RHEL7 / CentOS7 with screenshots. As a Linux admin, we may come in a situation to reset the forgetten root password on RHEL7 / CentOS7 systems.

If you are interested in learning, Request you to go through the below recommended tutorial.

How to Reset Forgotten Root Password of RHEL7 / CentOS7

Steps involved to recover/reset the root password:
1. Boot the Server to reset the root password.
2. Edit the Grub2 boot menu.
3. Remount the / partition to read/write mode.
4. Reset the root password.
5. Relabel the SELinux
6. Reboot the server and login with the new root password.

1. Boot the Server to reset the root password.

Boot the Server and interrupt the grub2 boot menu. Once you interrupted, your screen will be similar to the image below.

reset root password rhel7

2. Edit Grub2 boot menu.

Press “e” to edit the default boot OS, normally it would be the first line. Once you pressed “e”, find the words “rhgb quiet” in the vmlinuz kernel line as shown in the below image.

Resetting the Root Password of RHEL7

Replace the words “rhgb quiet” with “init=/bin/bash” and press “Ctrl + x” as shown in the below image. This will take us to the single user mode which allow us to perform the maintenance activity.

How to reset the root password on RHEL 7

3. Remount / partition to read/write mode.

By default root partition will be mounted as read-only in single user mode. If we want to reset the password, the passwd changes should be affected in /etc/passwd file. So it should be writable to do the passwd changes. So we make the / partition to read/write mode.

bash-4.2# mount -o remount,rw /

Reset Forgotten Root Password

4. Reset root password.

Lets reset the password of root with your new password using the below command, which will prompt to enter the new password for two times as shown in the above image.

bash-4.2# passwd root

5. Relabel SELinux

This is a  steps mandatory to ensure that the SELinux context for entire system is relabeled after reboot, If you ignore this step, you will not be able to login with your new root password.

bash-4.2# touch /.autorelabel

6. Reboot the server and login with the new root password.

Once you reset the root password, reboot the server using the below and login with your new password.

bash-4.2# exec /sbin/init

Once the server is rebooted, you can login with your new root password successfully.

Hope you have got an idea How to Reset Forgotten Root Password on Linux.

Keep practicing and have fun. Leave your comments if any.

Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.