In this article, we will talk about how to restore a forgotten or lost root password on Redhat and CentOS 7 operating systems. We will be explaining these processes on CentOS 7. Because we forgot the password of CentOS 7. These operations are also valid on RHEL. First, if our server is open, we restart it and click the “e” key when the boot screen comes up.
We find the line starting with Linux16. We come to the place where it says “ro”.
We delete the “ro” and write the line “rw init=/sysroot/bin/sh” instead.
Then we click the “CTRL+x” key to switch to recovery mode. We run the commands below in order. You can set our new password after typing the “passwd root” command.
chroot /sysroot passwd root touch /.autorelabel exit reboot
After running the reboot command, the SELinux relabeling process starts and may continue for a while depending on the state of your system. After the process is finished, our server will restart. Then we can login with our new password.