Method 1 : rd.break
Step 2: Find the linux line and enter a space rd.break at the end
then press ctrl+x
STEP 3: VIEW OPTIONAL STEPS
Enter: mount | grep sysroot
Here sysroot is mounted in the form of ro read-only, so it should be mounted in a readable and writable manner
Step 4: Mount /sysroot Read-Write
Enter: mount -o remount,rw /sysroot
After the modification is complete, enter mount | grep sysroot again to check, and found that ro has been changed to rw
Step 5: Change password
Enter: chroot /sysroot/
Enter the command to change the password again: echo "123456" | passwd --stdin root
(Here is to reset the root user's password to "123456")
Display successfully means the modification has been successful
6. Force reset the context of the file system
Input: touch /.autorelabel (note the space)
7. Exit exit, execute exit again, reset the file system context, there will be a percentage.
When the loading is complete, that is, all operations have been completed, only need to verify the login.
Method 2: init method
1. Start the system, and when the GRUB2 startup screen is displayed, press the e key to enter the edit mode. (same as the first method)
2. Add the following content at the end of the parameter line where linux is located:
(1) Find ro and modify ro to rw
(2) Add init = /bin/sh at the end
2. Press Ctrl+x to boot to the shell
3. Run passwd, and follow the prompts to modify the root password.
(Or use the following command to change the password: echo "new password" | passwd --stdin root )
Enter the new password at the prompt (the password entered here is invisible)
You also need to enter the confirmation password once (we can't see the password twice)
After success, it will prompt successfully
4. If the system has enabled selinux before, you must run the command: touch /.autorelabel, otherwise the system will not start normally.
5. Run the command: exec /sbin/init to start normally, or use the command: exec /sbin/reboot to restart
At this point, the second method of modifying the root user password is also completed.