Wednesday, July 22, 2015

How to reset root user's password in RHEL7

Problem working with VM's is that you might not use one for a long time and when you had to use it again, you probably won't remember the root user's password! Yeah, ran into that situation myself again today and here are the steps to reset root user's password in RHEL 7. This is a bit different to how we used to do in RHEL 6.x.

1. On the grub menu, press 'e' to enter edit mode.
2. Once in edit mode, look for the line starting with 'linux16', and replace 'rhgb quiet' with 'init=/bin/sh'
3. Press ctrl+x to start booting with the modified grub entries
4. The file system will be mounted in read-only mode. Remount it in rw mode using the below command -  
mount -o remount, rw /
5. Use passwd command to reset the password for root user
6. Execute below command to ensure the selinux contents of modified files are restored properly after reboot -
touch /.autorelabel
7. Execute exec /sbin/init to continue normal boot process or exec /sbin/reboot to reboot the system

Thanks to original poster.

No comments: