Forgot CentOS login password

First turn on the system and hold down the esc key

Insert image description here

Press the e key to enter editing options

Insert image description here

Move the cursor all the way down to linux16, add LANG=en_US.UTF-8, a space at the end, and then add init=/bin/sh

(Note: There is no linux16 line in the above picture, you need to slide it with the down key)
Insert image description here

Press Ctrl+x to enter boot startup, and enter this interface after success.

Insert image description here

Enter the following command

Mount to the root directory and change the ro (read-only) permissions to rw (read-write)

mount -o remount, rw /

Select the user whose password you want to change. Here, select the root user to make changes. You can change it to the user you need to change.

passwd root

Enter the same new password twice

If the password entered is too simple, a warning will be prompted (BAD PASSWORD: The password fails the dictionary check - it is too simplistic/systematic). You can ignore it and continue to enter the password.

If selinux has been turned on, you need to enter the command

touch /.autorelabel

Finally enter the command to restart the system

exec /sbin/init 或者 exec /sbin/reboot
Insert image description here

Guess you like

Origin blog.csdn.net/qq_49472679/article/details/126227863