centos7 forgot password change steps

Hi, friends, I stuck my head out again after being silent for a long time, this time I brought the steps of resetting the forgotten password of centos7 under linux, the personal test is effective~,

The first is to start centos, when the following interface appears: Then press E in the operating system to edit

Then you will see an interface like this

Move ↓ to the specified position

Then add the last line init=/sysroot/bin/sh after rw  

Add rd.break enforcing=0 or rd.break selinux=0 after UTF-8 (I used the previous command, the result is an error, but it can also be corrected)

Press ctrl + X to enter emergency mode and reset password

The filesystem is remounted as writable, change the root of the filesystem like this 

    chroot sysroot

Enter the passwd command, and then the command line prompts to change the root password 

Enter the password twice when prompted,

Updating the password file will result in an error in the SELinux security context file. Type the following command to relabel all files before the next system boot:

    touch /.autorelabel

Remount the system as read-only: 

    mount -o remount,ro / 

Type the exit command to exit the chroot environment: 

    exit

Type the exit command again to complete the initialization and complete the system boot. 

    exit 

So far, 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 and enter the password of the root user to log in successfully. If you can't jump to the login interface for more than 5 minutes, press Esc and it will appear

    Failed to load SELinux policy. Freezing

On the startup page when restarting, select the kernel you want to start and press E to enter the grub editing page.

Find the line of linux16, after the language is LANG=zh_CN.UTF-8, add selinux=0 or enforcing=0 to the space  (Note: I added selinux=0 to take effect.)

Then ctrl + x starts, and you will see the familiar login interface.

Modify the selinux configuration file and close selinux correctly ~!

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#    enforcing - SELinux security policy is enforced.
#    permissive - SELinux prints warnings instead of enforcing.
#    disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#    targeted - Targeted processes are protected,
#    minimum - Modification of targeted policy. Only selected processes are protected. 
#    mls - Multi Level Security protection.
SELINUXTYPE=targeted

Then restart, you will find that you can jump to the login interface, then enter root, enter the password you just set to log in, and then change the password over!!!

Guess you like

Origin blog.csdn.net/bruce_van/article/details/97580582