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.
DevOps Full Course Tutorial for Beginners - DevOps Free Training Online
Docker Full Course Tutorial for Beginners - Docker Free Training Online
Kubernetes Full Course Tutorial for Beginners - Kubernetes Free Training Online
Ansible Full Course Tutorial for Beginners - Ansible Free Training Online
Openstack Full Course Tutorial for Beginners - Openstack Free Training Online
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.
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.
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.
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 /
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.
0 Comments