If for whatever reason you need to reset root password on a Linux system, assuming you can access the GRUB boot loader, you probably will be able to reset root password using GRUB. To access the GRUB boot loader, you simply restart the operating system, and the GRUB boot loader menu should appear.
Press e to access the edit menu for the selected kernel. You should be presented with a screen that looks something like this.
Locate that line that begins with linux or linux16. If this line contains "rhgb quiet", remove "rhgb quiet". Add init=/bin/bash to the very end of the line. Note: The linux or linux16 information is in the Grub configuration file.
Press ctrl x to start the system.
You should now have a bash shell prompt. By default, the / (root) filesystem is mounted with the ro (read only) permissions. The mount command can be used to see this.
bash-4.2# mount | grep -w "/" /dev/mapper/centos_lv-root on / type xfs (ro, relatime,attr2, inode64)
Remount the / (root) filesystem with rw (read write) permissions.
bash-4.2# mount -o remount,rw /
Use the mount command again to confirm that the root filesystem now has rw permissions.
bash-4.2# mount | grep -w "/" /dev/mapper/centos_lv-root on / type xfs (rw, relatime,attr2, inode64)
Use the passwd command to reset root's password.
bash-4.2# passwd New UNIX password: ******** Retype UNIX password: ********
Create the hidden file .autorelabel in the / (root) directory to cause SELinux to automatically relabel the context of the / (root) filesystem.
bash-4.2# touch /.autorelabel
Ensure the hidden .autorelabel file was created.
bash-4.2# ls -la /
Boot the system.
bash-4.2# exec /sbin/init