Linux password forgotten? one trick solution


Table of contents

I. Introduction

2. Enter the editing interface

3. Single user mode

4. Change password

5. Update information

6. Exit

7. Verification


I. Introduction

  • Version: centos7.9, VMware15.5

When we are learning the linux operation level, the interview question may ask how to retrieve the root password. Let’s introduce it in detail below, and the actual test is effective.

2. Enter the editing interface

  •  First, restart the system. At this time, note that the time is only 5s countdown. Select the above one, press e to enter the editing interface.

3. Single user mode

  • After entering the editing interface, move the cursor to locate the ro indicated by the red arrow in the above picture
  • Replace ro with rw init=sysroot/bin/sh
  • After the replacement is complete, press ctrl+x to execute 

4. Change password

  • After entering this interface, enter the chroot /sysroot command
  • Then enter the passwd root command to change the password 

  • Don’t worry about this white box, it should be a coding problem, enter the password in the direction of my red arrow, press Enter and enter once to confirm. 

5. Update information

  • Type touch /.autorelabel
  • What it does : Next time you reboot the system, it will automatically relabel the SElinux filesystem

6. Exit

  •  Enter exit to exit, reboot to restart the virtual machine

7. Verification

  • It took a long time to re-enter, about 5 minutes, no problem 

  • Come to the graphical interface or the command panel to log in to the password we just modified
  • done ok

Guess you like

Origin blog.csdn.net/qq_53673551/article/details/125571390