What should I do if Linux forgets the root password? How to reset root password?

Situation description:
When we forget Linuxthe rootpassword, how to reset rootthe password?
Mine is Centos7.9the version.

Start the server
Start the interface, press the up and down keys, select the first one, and then press e.
insert image description here
Enter the editing page
insert image description here
Use the up, down, left, and right keys to move the cursor to the red box in the figure, which is LANG=en_US.UTF-8the back
, and then input: init=/bin/sh. Then, press Ctrl+xExecute Command.
insert image description here
Enter, 单用户模式
insert image description here
after entering this mode, the following is the command line. Enter the command and Enterexecute it .
Enter the commands one by one and press Enter to execute:
mount -o remount,rw /
passwd
insert image description here
After entering the new password,
touch /.autorelabel
exec /sbin/init
it takes a long time to enter the process, about a few minutes.
insert image description here
The system automatically restarts and enters the login page.
Use the password you just set to log in root.

Guess you like

Origin blog.csdn.net/Brave_heart4pzj/article/details/130854670