Resetting the Root Password in RHEL7
This is one of the exam topics in the RHCSA exam that you should know. I've struggled with it a bit as there was no official documentation on this until July, a bit late for me! I've listed below the steps to help me recall this in future. There is also official documentation here:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sec-Terminal_Menu_Editing_During_Boot.html#sec-Recovering_Root_Password
Press any key at the Grub boot loader
and then e to edit the default option
Scroll down to the line starting with
initrd16 and press the left arrow once until you get to the end of the line
above it ending in LANG=en_IE.UTF-8 and append as follows:
LANG=en_IE.UTF-8 init=/bin/sh
Press CTRL-X to boot and you’ll get
to a sh-4.2# prompt. Enter the following commands:
mount
-o remount,rw /
passwd
root
touch
/.autorelabel
(optional - could delay VM boot excessively)
exec
/sbin/init
(continue booting VM or you could power cycle VM)
Note: commands entered in the bash
prompt are not echoed to screen. I get palindrome warnings but this doesn't stop it working unless you type more than 1 character – make sure you enter a single
character as the new password only at this point you can change it again later.
Maybe it's something I'm doing but the above steps work and it updates the root password fine, then you just have to edit it later after the O/S loads to something more suitable. You can prep a backdoor account using visudo before you carry this out on your Lab VM, just adjust it as follows:
root ALL=(ALL) ALL
student ALL=(ALL) NOPASSWD: ALL