How to Reset Root Password in RHEL 7
Setting up theÂ rootÂ password is a mandatory part of the RedÂ Hat EnterpriseÂ LinuxÂ 7. If you forget or lose your password, it is possible to reset it by certain steps. Now it is known as Emergency mode in RHEL 7, Previously in RHEL 5/6 it was â€œSingle User Modeâ€. Â In GRUB 2(For RHEL7), resetting the password is no longer performed in single-user mode as it was in GRUB included in Red Hat Enterprise Linux 6.Here we use some other method.
TheÂ rootÂ password is now required to operate inÂ single-usermode as well as inÂ emergencyÂ mode.
Steps for Resetting the Root Password
- Please follow this procedure carefully, any mistake can make your system unstable.
- Start the system and, on the GRUB 2 boot screen, press theÂ eÂ key for edit.
- Add the following parameter at the end of theÂ linuxÂ line.
Â Â Â Â 4. Â Now pressÂ Ctrl+xÂ to boot the system with the parameter. The shell prompt appears. This reboot will take you to the /sysroot folder. Here /sysroot is the place where everything is kept before it gets mounted on the / , during the Booting process, after the booting, everything is mounted on the / folder. By default the /sysroot folder is mounted with read only (ro) permissions, so in order to make the changes we have to remount /sysroot with read write permissions(rw). You will not be allowed to change the password if the file system is not writable. To remount the file system as writable, run the command:
#mount -o remount,rw Â /sysroot
Now we have to change our chroot to /sysroot
Â 5. Â Â Run theÂ passwdÂ command and follow the instructions displayed on the command line to change theÂ rootÂ password. Note that if the system is not writable, theÂ passwdÂ tool fails with the error.
6. Â Â Once you login into your system change the SELINUX Context of /etc/shadow file to default, because the kernel disable the SELINUX temporarily and because of the SELINUX system will not start during the next boot. To make sure that SELinux context of the files that were modified is restored properly after boot, run
7. Â Â Now for logout & reboot type following command