Sunday, 12 March 2017

Reset root password in RHEL7


Resetting root password in RHEL7 is slightly different than the older versions.

Reboot and edit grub2:


Reboot the system and press any key to stop the auto-boot from the default kernel. Press "e" after selecting the kernel line.





Append rd.break to kernel:

When we are in edit mode, go to the line starting with linux16 and append rd.break to the end of the line.





Reboot the system:

Press CTLR+x after appending the rd.break to the kernel. This will reboot the system into emergency mode.









Remount sysroot:

First we will remount the sysroot file system in read write mode and then use chroot to got into a chroot jail.






Reset root password:

Finally type password command in the command line and set the new password for root user. You might get some warnings like "password fails dictionary check" if your password is week. You may safely ignore the warning and set the password you want.













SELinux relabeling:

Make sure that all unlabeled files (including shadow file) gets relabeled during booting. Touching the hidden file autoleabel instructs SELinux to relabel the files changed outside of its regular context, like the file /etc/shadow.







Sync:

To flush all cache to disk, type the command.






type twice the exit command to leave the chroot environment and logout. The system will apply some SELinux contexts and reboot. You can now login using your newly set root password. 

No comments:

Post a Comment