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
- First restart the server , When you see this screen, select the first item , Press down e Key to edit
2. Now enter the following interface
Can press ↑↓ key
You can find ro This one , Change it to rw init=/sysroot/bin/sh
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 .
4. After restart , Sign in root The account needs to enter the new password just changed .