当前位置:网站首页>Server root password forgotten, use centos7 emergency mode to change the root password

Server root password forgotten, use centos7 emergency mode to change the root password

2020-11-10 15:10:35 Philosophy of life

One . Actual combat scene

Company one centos7 The server root I forgot the password , You need to modify root password , Retrieve root identity .

Two . Enter emergency mode to modify root password

  1. First restart the server , When you see this screen, select the first item , Press down e Key to edit

image-20201014020904603

2. Now enter the following interface

image-20201014021008236

Can press ↑↓ key

image-20201014021145580

You can find ro This one , Change it to rw init=/sysroot/bin/sh

image-20201014021923274

After a change , Press down Ctrl+X Enter emergency mode , The principle of this step is : Start a shell Environmental Science , But the system didn't really start up .

3. Change one , Then change the password
chroot Command is used to run instructions in the specified root directory ,chroot, namely change root directory ( change root Catalog ). stay linux In the system , The default directory structure of the system is based on /, That's root (root) At the beginning . But in the use of chroot after , The directory structure of the system will take the specified location as / Location . after chroot After the command , The directories and files read by the system will not be under the old system root, but under the new root ( That is, the new location assigned ) Directory structure and files .

​ Be careful : If the system selinux It's on , Then you need to execute the command :touch /.autorelabel To update system information , Otherwise, password change will not take effect after restart
​ exit Exit the current root ,reboot Restart the system .

image-20201014022415020

4. After restart , Sign in root The account needs to enter the new password just changed .

版权声明
本文为[Philosophy of life]所创,转载请带上原文链接,感谢