Reset the root password of RHEL/CentOS 7
This article provides the information about resetting forgotten root password in RHEL/CentOS 7 and Fedora Linux distros. This is the easiest method to reset the root password for RHEL/CentOS7.
Suggestable Read: How to reset root password in RHEL/CentOS Linux v6.x
Also Read: Linux Booting Process steps – RHEL/CentOS 7
What is new in root password reset in RHEL/CentOS 7?
If you have forgotten your root password on RHEL/CentOS 7 system, resetting root password procedure is a little bit different to RHEL/CentOS 6.x.
RHEL/CentOS 7 system is now using systemd instead of init.
If you have any user on the server which got, root level sudo, that account can be used to become root and then reset the password online.
This Solution should work for all RHEL based systems like CentOS, Fedora, Scientific Linux and Oracle Linux 7
To break the root password of a system (virtual machine), you need to perform the following steps:
- Access to reboot the System.
- System/Console for accessing the GRUB2 ( boot loader)
Steps 1: Take console and reset or restart the server.
Physical Box: IMM/ILO/ILOM/iDRACK, etc
VMware: vSphere Client
KVM: Virsh Console
After rebooting your virtual machine, you will be prompted to select the kernel.
Step 3: Select the kernel entry and press “e”
Step 4: Select the line starting with “linux16” and update “ro” entry to “rw init=/sysroot/bin/sh” .
5. Press Ctrl+X or can also press F10 key to boot the OS in single user mode.
6. When you see the shell prompt, execute the following command to mount the root to /sysroot/
Mounting the root partition.
# chroot /sysroot
7. Reset the root password: Execute the following command to set a new password for root.
# passwd root
8. After updating the new password, update SELinux settings.
# touch /.autorelabel
Keep patience, relabeling the file systems may take some time.
9. Exit single user mode : Execute the following commands to exit from single user mode
10. Finally, execute the following command to reboot your virtual machine.
Reboot the system