Root Password

root password

This tutorial is to reset the root password for Fedora, Red Hat, Centos, Rocky Linux, Alma Linux, etc., any Red Hat based distro.

Have you ever forgotten your root password or maybe you mistyped it twice when changing it? Yes, that has happened *cough* *cough*. πŸ˜€ This is a relatively easy fix as long as you have console access to the computer so let’s start.


Start or restart the computer. When the GRUB menu comes up, press e.

Next step is to write “rd.break enforcing=0” without the quotes. See the picture below. If your GRUB loader has rhgb quiet at the end of the line, remove it. RHGB stands for Red Hat Graphical Boot and Quiet hides most of the boot messages and we want to see those so remove it. Don’t worry about “\” at the end of the lines, it tells us that the line continues below. When you are done editing the line press Ctrl+x to continue the booting process.

Now we need to run a few commands.

 mount -o remount,rw /sysroot 

 chroot /sysroot 

 passwd 

If you don’t specify a user, you will change the password for the root user.

 exit 

 mount -o remount,ro /sysrootΒ 

 exit 

Now the machine boots and after it boots the new password works!

But we need to fix Selinux. πŸ˜‰

 restorecon -v /etc/shadow 

 setenforce 1 

Let’s reboot.

 reboot 


Done!

Resetting the root password shouldn’t give you any problems but my process is two commands longer than usual because I ran into issues. Selinux wasn’t relabeling in VirtualBox so the new password didn’t work.

Here is the shorter way which should work but VirtualBox was giving me a hard time. Maybe you want to try it and see if it works on your computer. If you try this method, don’t write “enforcing=0″ in the Grub menu. Only “rd.break.”

 mount -o remount,rw /sysroot 

 chroot /sysroot 

 passwd 

 touch /.autorelabel 

 Ctrl-D 

 Ctrl-D 

Have fun. 😎


Leave a Reply

Your email address will not be published.