How to Reset Root Password on Red Hat 7
How to Reset Root Password on Red Hat 7/CentOS 7/Red Hat 8/CentOS 8
The root account is a special user that have all the administrative rights to perform the task and operations on Linux base operating systems (Red Hat 7/8, CentOS 7/8 etc.). Sometime System Administrator forget the root password and have no other user to login on machine that have sudo rights that is equivalent to root user for reset the root password or perform all administrative task. Best administrator have at least have one more user other than root user to perform all administrative task with sudo rights. If other user have sudo rights it can execute any command means even to reset the root password of the machine.
In this lab we will reset root password from grub bootloader boot options, you must have console access of the machine because you cannot reset the password by use of SSH because grub bootloader boot options is not available through SSH.
What is GRUB?
Grub stand for GNU GRand Unified Boot loader. The Grub enable the operating system to boot, in grup you need to give a right argument for reset the root password.
To edit the grup parameter reboot the operating system then edit the below mention image highlight option “Red Hat Enterprise Linux Server (3.10.0-1136.el7.x86_64) 7.9 (Maipo)” by press e, in you scenario it may be different.
rhgb = redhat graphical boot, in quiet hides the majority of the boot options. rd.break is a preferred method to reset the root password if system administrator forget the root password, here enforcing=0 means it’s disable the SELinux if it is enable.
After replace "rhgb quiet" parameters with "rd.break enforcing=0", press Ctrl+X to start the boot process into the root system.
In the below image you can see that CentOS Linux operating system is boot into the root system
Type the below mention command to remount the sysroot file system for read and write operation, because it is on read only mode.
mount -o remount,rw /sysroot
To reset the root password from root system, type the below mention command
Now use command “passwd” to reset the root password of CentOS 7/Red Hat 7/CentOS 8/Red Hat 8 operating system.
Password of root has been successfully change. To move back to the switch_root, type two times exit.
Type the below mention command to remount the sysroot filesystem as read-only.
mount -o remount,ro /sysroot
Finally, exit from the session for operating system reboot.
To verify the root user with it’s newly reset password.
Type the below mention command to restore the shadow file, the purpose of shadow file to encrypt the user password. Therefore, after perform all the activity need to update the file by use of command “restorecon”. The purpose of command “restorecon” is modify the SELinux context of file and directory, actually it is use to restore the default context of file and directory as per the SELinux policy.
If you have SELinux in enforcing mode, you need to modify the file again to set SELinux as enforcing.
Thanks For Read this Article