Thursday, September 7, 2017

Reset Root Password in RHEL 7 and CentOS 7


1. Restart the machine using Ctrl + Alt + Del and Interrupt the count down by pressing any key
2. Select the default menu and press “e” to edit the current grub entry.
3. Using the cursor navigate to line “linux16 and add entry “rd.break” at the end. This will break just before control is handed from the intramfs to the actual system.
4. Press “Ctrl+x” to boot using the modified config
5. At the switch_root prompt, remount the /sysroot file system in read-write mode.
    #mount –o remount,rw /sysroot 
6. Using the command “chroot /sysroot” to change the current root directory
7. Change the password using “passwd” command
8. Configure the system to automatically perform a full SElinux relabel after reboot. Since the password command recreated the /etc/shadow file without any SElinux contest.
    #touch /.autorelabel
9. Type “exit” twice and reboot the system in normal mode.

No comments: