This is what you need to reset CentOS 7 root password when you forgot it. To reset CentOS 7 root password you don’t need anything just a simple boot will help you perform the entire process of resetting the lost password of CentOS Linux.
I’m testing this on a virtual machine. It works perfectly and I have reset CentOS 7 Lost password with this method many times at home and work office. So try to not destroy your CentOS Linux server in a real network environment.
Reset CentOS 7 Root Password
Note: This tutorial will only work if you have direct access to the machine or serial terminal access with boot menu options. You can’t reset the root password if you’re remotely connected since you need boot menu access.
1. For the first time when you boot your CentOS system, on the boot loading page, select the CentOS Linux (***) 7 (Core) and press “e” for editing the selected item.
It will allow you to edit the sysroot file for resetting the lost CentOS Linux password. Make sure you do all tasks correctly as you see on the screenshots.
2. Now, scroll down to the list until you see the line underlined below (ro). Just delete the selected yellow code and replaced with the next screenshot code.
3. Here you just need to do is change that “ro” to “rw” in order to start next into a bash shell. It should look like this “rw init=/sysroot/bin/sh“. See the screenshot as well.
4. After changing the code, press “Ctrl+X” on your keyboard to start into single user mode using the bash shell specified above. In this mode, you are able to change CentOS root password.
5. Finally, type “chroot /sysroot” command and press Enter. Next type “passwd root” to change the root password. Type the new password twice and press Enter.
On the final step, after creating the password, type the “touch /.autorelabel” command to update SELinux parameters. When done, exit and reboot the system. centos 7 root password default
That’s all you have to learn to reset CentOS 7 root password default or change root password CentOS 7 using command line.