How to reset root password on CentOS

As we wrote earlier, you can lose your password or simply forget it. But this is not a reason to worry and you do not have to reinstall the OS on the server and lose all the files, as the password can be easily reset.

How to reset root password

To reset the password, we must enter the server control panel and click on the VNC button.
We reboot the server using the “CTRL + Alt + Del” button, immediately press the button and wait for the GRUB bootloader to appear and immediately press the letter “e” to start editing the boot file.

Now we have to find the line where “ro” is located.

Then instead of “ro”, we write “rw init=/sysroot/bin/sh” so that this line looks exactly like this and press “CTRL + X” to boot the OS in this mode.

As soon as the OS has booted, execute the following command:

chroot /sysroot

And then change the password using the “passwd root” command.

After we reset the password, we press the “CTRL + Alt + Del” button, restart the server and then enter it with a new password.