How to Reset Lost Or Forgotten Root Password Of Red Hat and CentOS 7 Linux

What if, root or superuser password is lost or forgot in RedHat/CentOS 7 Linux? This is the quick guide or method to reset forgotten root password without any additional recovery tools. But you need to have physical access of the system. I have tested this on RedHat 7 Linux and the same steps can be followed to reset lost or forgotten root password on CentOS 7 Linux as well.

There are two ways to reset forgotten root password in CentOS and RHEL 7 Linux.


1. With recovery media
2. Without recovery media
In this post, we are resetting root password without using recovery or rescue media.


Below are the steps involved.



1. Boot your system in GRUB 2 menu

We can see the GRUB 2 menu when system boots up, press ESC to intercept and enter into GRUB 2 Menu.

2. Editing GRUB 2 Menu

Press e to edit GRUB 2 menu, you can see the similar screen as below. Scroll down and search linux16 or linuxefi (if your system is efi enable) and move to the end of the line. Add the string init=/bin/bash to the end of line after giving space. Also remove the rhgb quiet from that line.

3. CTRL+x to boot in single user mode.

Once you have done that change, press Ctrl-x to accept the changes it will boot into runlevel 1 (single user mode).

4. Run load_policy to load the installed policy file into the kernel.

# /usr/sbin/load_policy -i

5. Use mount command to remount the root filesystem in read-write mode

# mount -o remount,rw /

6. Change root password

Now, we can change root password with passwd command as below.

7. Run the exec /sbin/init command

System boots up, you can try login with newly recovered or reset root password (if root user is enabled).

# exec /sbin/init
That’s it. In this post we have seen to reset or recover lost or forgotten root password in RHEL/CentOS 7 Linux. Please share it with others and follow us on our Facebook Official Page.


Leave a Comment