Reset Root Superuser Password in Centos 7 or 8

Sometimes it happens that system administrators forget the superuser password or, for example, a server which there is no information. In these cases, we need to figure out what kind of server it is and what service is running on it. But how to get into the system if we do not have a password?


This theoretical part explains the steps to follow when resetting a password:
Reboot the server and when the GRUB menu appears select the kernel version you want to boot and press E to edit the selected boot item:

Next on the screen you will see the kernel boot options. Find the ro parameter:

Change the ro options to rw init=/sysroot/bin/sh as shown below:

After changing the parameters, press CTRL + x and you will be taken to single-user mode.
In single user mode, run the following commands to mount the root filesystem in read-write mode.

# chroot /sysroot

And now you have the option to reset your password

# passwd root

After changing the password, enter the following commands to change the SELinux context.

# touch /.autorelabel

And finally exit and reboot into normal mode

# exit
# reboot

You can now log in with a new password.

Leave a Reply

Your email address will not be published. Required fields are marked *