[centos 7] Administrator [root] forgot password solution

If you forgot your root password on CentOS 7, you can reset it by following these steps:

1. When the system boots, select the CentOS 7 entry to start and press the "e" key on the keyboard to enter edit mode.

2. In edit mode, find the line starting with "linux16" and add the "rd.break" parameter at the end of the line.

Download:
linux16 /vmlinuz-3.10.0-1127.el7.x86_64 root=/dev/folders/centos-root ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet 【rd.break】 】

3. Press "Ctrl + x" or "F10" to start the system.

4. The system will enter emergency mode. At this point, you will have a read-only root filesystem.

5. Enter the following command to remount the root file system in writable mode:

mount -o remount,rw /sysroot

6. Enter the following command to switch to the root file system: 

chroot /sysroot

7. Enter the following command to change the root password:

[passwd root] Enter the new password as prompted and confirm.

8. Update the SELinux context: 

touch /.autorelabel

9. Exit the chroot environment:

exit

10. Enter the following command to remount the root file system in read-only mode:

mount -o remount,ro /sysroot

11. Enter the following command to restart the system:  

reboot

PS】The system will restart and you can log in to CentOS 7 using the newly set root password. Please note that these steps only apply if you have physical access. If you are working on a virtual machine or remote server, make sure you have the appropriate permissions and access.

Guess you like

Origin blog.csdn.net/weixin_71435518/article/details/131703392