To reset the root password for CentOS 6:
Boot Computer and Interrupt while booting at GRUB stage hitting ‘arrow‘ keys or “space bar“.
Type ‘a‘ to modify kernel argument. Anytime you can cancel typing ‘ESC‘ key.
Append 1 at the end of “rhgb quiet” and press “Enter” key to boot into single user mode.
Type command “runlevel” to know the the runlevel where you are standing. Here “1 S” state that your are in a single user mode.
Type ‘passwd‘ command without username and press ‘Enter‘ key in command prompt. It’ll ask to supply new root password and re-type the same password for confirmation.
Reboot
# shutdown -r now
CentOS 7
At the boot menu, press e to edit the existing kernel (Core)
Next, scroll down to the list until you see the line underlined below ( ro ) . What we need to do is change that ro to rw and start into a bash shell. It should look like this rw init=/sysroot/bin/sh.
Change the ro line to rw and add init=/sysroot/bin/sh
After changing that, 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
# chroot /sysroot
Finally, run the commands below to change the root password.
# passwd root
You’ll be prompted to create and confirm a new password. After creating the password, run the commands below to update SELinux parameters
touch /.autorelabel
Reboot