If you lost your CentOS 7 VPS or server password, you can reset root password of CentOS 7 in less than 5 minutes with console access.
1- Restart the system (hard reset or by pressing the ctrl + alt + delete) and switch to the boot grub menu. During the start up, there will be instruction on how to bring up the boot menu. In many cases “f11” key does the job.
2- In the boot menu you will see some lines, highlight the first one and as you see in the below picture, hit “e” to edit the line.
3- Now you are in a text editor. Look for the line which included /vmlinuz and move the cursor to “ro” which is usually located after the root path (root=xxx/xxx/xxx). Change “ro” to “init=/sysroot/bin/sh”.
4- No press Ctrl + X to restart the system in single user mode with root access!
5- Here we need to gain the system root, so issue this command:
chroot /sysroot
6- Now you are logged on as root user. So reset the password:
passwd root
It asks twice for the new password.
7- We need to update the selinux policy at this level:
touch /.autorelabel
8- Exit root and reboot:
exit
reboot
Now you can login with the password you chose at step 6 and root username.