Centos7 reset root password (detailed version)

Time:2021-1-28

 

The root password is modified as follows:

Step 1: press the “e” key when the following interface appears

此图像的alt属性为空;文件名为image-33.png
 
 

Step 2: after pressing the “e” key in step 1, the following interface will appear. Press the ↓ key all the way to the bottom to find “lang = zh”_ CN.UTF -8 “, add” init = / bin / sh “after this sentence, and then press Ctrl + X to enter single user.

此图像的alt属性为空;文件名为image-35.png
 
 

Step 3: mount the file system in writable mode: Mount – o remount, RW/

Note: as for why we need this command, it is because our / file system is in read-only mode and cannot be modified by default after entering single user mode. At this time, we need to use a command: Mount – o remount, RW / to make our / path file system in read-only mode, so that we can modify it freely.

此图像的alt属性为空;文件名为image-34.png
 
 

Step 4: execute the passwd command and modify the root password. The password should be entered twice and the two passwords should be consistent.

此图像的alt属性为空;文件名为image-36.png
 
 

Step 5: if the system has enabled SELinux before, you must execute the following command, otherwise you will not be able to start the system normally: touch /. Autorelabel. Then execute the command exec / SBIN / init to start normally, or use the command exec / SBIN / reboot to restart.

 

Source: https://mefj.com.cn/lur1974.html