Monday, August 25, 2014

Resetting root password in Red Hat and CentOS 7

This process was a bit confusing and according to the official Red Hat documentation, has a few missing steps. I found the answer from another blog and this helped finally get to the real fix. Note, this is tested on CentOS7 on a VMware Workstation Virtual Machine.

 1. During the boot process, press the E key at the Grub2 menu.

2. Scroll down using the arrow keys (not the Vi method) to the line starting with "linux". It would look like this "linux16 /vmlinuz-3.10.0..."

3. Remove the following entries from that line, "rhgb" and "quiet". If you leave these, they mess up the console and do not allow a password more than one character.

 4. Add the following to the end of the line.


5. Press ctrl+x to continue the boot process.

 6. Once the system is booted, you will be at the root user in single user mode. But this is a read only file system. Validate this by using the following command. This should fail. # touch /tmp/test

 7. You need to mount the / filesystem. Use the command as follows.

 # mount -o remount, rw /

8. Test again that you can write to / after the remount.

# touch /tmp/test

 9. Change the password for root.

 # passwd

 10. Touch the following file as a fix file process. This is for SELinux.

 # touch /.autorelabel

 11. Finally start the normal boot process. In some references you can use the reboot command but in my testing, it was not as stable.

 # exec /sbin/init

 12. Now login with the new password!

No comments: