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.

how to reset root password on centos 7
Find “rhdb quiet” parameters and replace with "rd.break enforcing=0"

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.

how to reset root password on rhel 7

After replace "rhgb quiet" parameters with "rd.break enforcing=0", press Ctrl+X to start the boot process into the root system.

how to reset root password on centos 8

In the below image you can see that CentOS Linux operating system is boot into the root system 

how to reset root password on red hat 7

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

how to reset root password on red hat 8

To reset the root password from root system, type the below mention command

chroot /sysroot

reset root password on linux

Now use command “passwd” to reset the root password of CentOS 7/Red Hat 7/CentOS 8/Red Hat 8 operating system.

passwd

reset root password on centos 7

Password of root has been successfully change. To move back to the switch_root, type two times exit.

switch_root:/# exit
exit

reset root password on centos 8

Type the below mention command to remount the sysroot filesystem as read-only.

mount -o remount,ro /sysroot

reset root password on rhel 7

Finally, exit from the session for operating system reboot.

exit

reset root password on rhel 8

To verify the root user with it’s newly reset password.

how to reset root password on centos 7

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.

restorecon /etc/shadow

how to reset root password on rhel 7

If you have SELinux in enforcing mode, you need to modify the file again to set SELinux as enforcing.

cat /etc/selinux/config

how to reset root password on centos 8

Thanks For Read this Article

Comments