Note: This trick will only work if you have direct access to the machine. Since you need boot menu access to do this trick, you can’t reset the root password if you’re remotely connected.
How To Reset Your Forgotten Root Password On CentOS 7 Servers
Step 1: To get started, turn on your machine. To select the operating system kernel to boot in, you will have 5 seconds at boot menue.
Step 2: After booting your machine, press e to edit the existing kernel (Core) at the boot menu.
Step 3: Next, scroll down to find the line including ( ro ) . You must change that ro to rw and start into a bash shell.
Step 4: To start into a bash shell you must add init=/sysroot/bin/sh to this line too. The line must be like rw init=/sysroot/bin/sh as you see in the following image.
Step 5: Now, press Control + X or Ctrl + X on your keyboard to start into single user mode using the bash shell specified above. In this mode, we’re going to change the root password.
In the single user mode, run the command as shown below
Finally, run the commands below to change the root password.
It will ask you to create and confirm a new password. To update SELinux parameters, after creating the password, run the commands below:
ُStep 6: Exit and reboot your system and login using new password.
Congratulations! You have learned How To Reset Forgotten Root Password On CentOS 7.
If you are facing any problem with the steps, fell free to comment here. We will help you to solve the issue.