Centos7 Forgot Root Login Password Solution

1. Restart/start the computer and press the e key when the following interface appears, or keep pressing the e key when the computer is turned on.

2. Press e on the keyboard to display the following interface (can be pulled down), which needs to be edited and modified: ro is changed to rw init=/sysroot/bin/sh

After modification:

3. Press Ctrl+x to start in single-user mode (enter rescue mode).

4. Use  the chroot  /sysroot command to access the system

5. Enter the passwd command, and then the command line will prompt you to change the root password.

6. Updating the password file will cause SELinux security context file errors. Type the following command to re-mark all files before the next system boot to make SELinux take effect. If not executed, the modified password will not take effect.

touch /.autorelabel

7. Exit chroot exit

8. The password has been changed successfully. After completing the last step of exit, you will wait a little longer, and then you will enter the startup page. After entering the password of the root user, you can log in successfully.

Guess you like

Origin blog.csdn.net/cyl101816/article/details/129400476