CentOS 7 / RHEL 7 : Reset / Recover forgotten root password
October 11, 2014 by sharad chhetri 4 Comments
In this post we will learn, how to reset / recover forgotten root password on CentOS 7 / RHEL 7 (Red Hat Enterprise Linux 7). On RHEL 5/6 or CentOS 5/6 series , the method of resetting forgotten root password was same. In latest RHEL 7 / CentOS 7 this time we have found some difference in steps to reset the forgotten root password.
Earlier, root password were used to recover from runlevel in case the boot loader password is not set.
Reset / Recover forgotten root password on CentOS 7 / RHEL 7
Follow the given below procedure to reset forgotten root password.
Step 1: Reboot or start the system, edit grub2
Restart/start the system and on getting GRUB 2 boot screen, first press ESC
key so that screen get stopped. Then press e
key for editing.
Step 2: Initialize the /bin/sh
Now in next screen, scroll down with the help of arrow key and search for any of these two keyword linux16
or linuxefi
on UEFI systems.In our case, we have linux16.
Disable rhgb and quiet parameters in order to enable system messages.
In first screenshot you can see, we first scrolldown to line starting with keyword calledlinux16
. Now remove the parameter rhgb
and quiet
.
In second screenshot you can see, we have removed the rhgb
and quiet
parameter
Add the below given parameter at the end of line, to initialize the sh shell.
init=/bin/sh
Now press CTRL
with x
keyword to boot the system.
Step 3: Remount / root partition , reset root password and autorelable
The filesystem will be in read only mode, hence run the below given command so that you can write on filesystem
mount -o remount, rw /
Now reset root password with given below command
passwd root
Reconfirm the root password.
NOTE: In case system is not writable, the passwd tool fails with the following error:Authentication token manipulation error
Now run the below given command for relabeling the SELINUX
touch /.autorelabel
Now restart the system. You can use any one of the command.
exec /sbin/init
OR
exec /sbin/reboot
You will see the system is going to reboot and stuck for a short time. Just wait for a few seconds or minute. Keep pay attention that the screen is stopped when SELIUX relabeling info message appeared on screen.
After a few moment, you will see at the bottom of screen some numerical percentage is running. It states about the completion of selinux relabeling in percentage. After completing 100% , the system will be rebooted.
After successful booting, you can use your new root password for login into system.