Root password recovery is one of the skills that should be in the tool belt of any Linux Systems Administrator out there. This and setting interfaces addresses are probably among the top two skills that it is simply unacceptable to not know. In the most recent release of RedHat Enterprise Linux and CentOS version 7, RHEL7 and Cent7 respectively this procedure has changed slightly. There seems to be a lot of misinformation on how to complete this once basic task.
Even RedHat’s own article is a much greater number of steps that has the admin using features like sysroot jails and SELinux labels to accomplish the task at hand. RedHat’s recommended instructions can be found here:
RedHat Systems Administration Guide
Next I’ll show you my Bullet Proof way to recover and reset root’s password the easy way.
Step 1.
Reboot the box using the /sbin/reboot command or init 6.
In the grub menu press the tab key to interrupt boot and the e key to directly edit the grub stanza. Pay close attention and search for the line that contains linux or linux16.
Step 2.
Scroll until you find the part of the stanza with rhgb quiet.
Replace that part of the stanza with init=/bin/bash.
Press the ctrl + x key to continue booting.
Step 3.
Now you should have a prompt that looks like this:
#bash-4.2
Type mount to see that /root is mount “read-only”.
Step 4.
Perform a remount of the root partition by typing:
mount -o remount,rw /
This will remount the root partition read/write.
You can validate by using the mount command to double-check.
Step 5.
Set root’s password using passwd .
passwd
Type the “new” password twice.
Step 6.
This is very important
If this system is running SELinux you will need to trigger a relabel.
touch / .autorelabel
Step 7.
Trigger systemd to boot the rest of the way and relabel.
exec /sbin/init
>Note that this may take a while depending on the size of disk and number of files.
Step 8.
Sign in with your new root user and WIN!
Please send feedback or questions to the@bulletproofsysadmin.com or tweet @bltpr00fadm1n.
Thanks for following along.