How to reset the root password in a Red Hat Enterprise Linux

If you are studying for the Red Hat Certified System Administrator (RHCSA) exam, the process to reset the root password in a Red Hat Enterprise Linux (RHEL) is critical for your success, and to be honest, it will save you every single time that you are stuck on a server. The process is simple, and it starts when the system is booting up. When restarting a Linux server, wait for the GRUB menu to be displayed, press e to edit the current version kernel.

reset root password

Find the line that starts with linux and has /vmlinuz as the second parameter o the same path. Go to the end of that line, and add the string rd.break at the end, and then hit Ctrl-x to break the boot process by intercepting the process before it is moved to the systemd (regular flow).

The following step is not required and not even documented in the Red Hat official documentation. I do use this step to help me to memorize the next steps. Our focus is on the sysroot folder.  Keep in mind that we are breaking the boot process, and we are one step before the systemd.

mount -l | grep sysroot

The sysroot is mounted in read-only mode, which does not help us to reset the password because the changes will not be saved. Our first step is to remount as read and write.

mount -o rw,remount /sysroot

The final step is to chroot jail, which means that we are going to go inside of a box, and everything that will exist for us will be inside of that folder.

chroot /sysroot

Now that we have access to a console. We can go ahead and change the password, and the final step is to add a file .autorelabel, which will instruct SELinux to relabel on the next boot.

passwd root
touch /.autorelabel

Type two times exit, the first to leave the chroot jail, and the second to leave the current rd.break session, which will trigger a restart of the server.

The entire process described in the previous step can be seen in the image below.

reset root password

And just like that, you have reset the root password.

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top