Root password resetting in RHEL – 7

Reset the root password on Redhat enterprise Linux 7 (If you have lost it).  Unlike the previous  version of RHEL releases , REHL 7 brought special attention by bringing the lot of new features  on it.  You need to follow some special instruction on Redhat Enterprise Linux 7 to break the root password since SE-Linux is enabled by default. In RHEL 6 , if you start the system in runlevel 1 , you will get the root prompt to reset the root user password.

1.  Reboot the system.

2.  In the grub menu, press escape key to prevent the system from booting. Edit the grub menu by pressing “e”

3. Press the arrow keys to get the “linux16” line and press “end” key. This will take you to the end of the line. Here add ” rd.break  console=tty1 ”  like below. Press control-x to boot the system

4. When you boot the system using “rd.break” ,  system will be directly mounted on /sysroot in read-only mode. Let me remount it in read/write mode.

switch_root:/# mount -o remount,rw /sysroot

5. Switch into a chroot jail, where /sysroot is treated as the root of the filesystem tree.

switch_root:/# chroot /sysroot

6.Set the new root password. (please update the CMDB immediately !)

sh-4.2# passwd root
New password: 
Retype new password:
passwd:all authentication tokens updated successfully.

7.By default, SE-Linux will be enabled on RHEL7 . So create a blank file in the name of “.autorelabel” under root.

sh-4.2# touch /.autorelabel

8. Exit from the chroot jail and exit from the initramfs.

9. System will reboot and perform a full SELinux relabel , then  reboot again.

10. once the system is rebooted, you will be able to login with new root password which you have set it .