Linux system modify root user password

Method 1 : rd.break

Step 1 Restart the system and press the e key on the interface shown in the figure below

 

 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)

insert image description here

 

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

insert image description here 

 2. Press Ctrl+x to boot to the shell

insert image description here

 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 )

insert image description here

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

 insert image description here

4. If the system has enabled selinux before, you must run the command: touch /.autorelabel, otherwise the system will not start normally.

 insert image description here

 

5. Run the command: exec /sbin/init to start normally, or use the command: exec /sbin/reboot to restart

insert image description here

At this point, the second method of modifying the root user password is also completed. 

Guess you like

Origin blog.csdn.net/m0_66185683/article/details/129617599