Reset forgotten root user's password

Reset forgotten root user's password

 

 

Experimental environment: There is a virtual machine Linux system that has forgotten the password of the root user, and cannot use the root user to log in to the system. It is now required to reset the root user password so that the root user can log in to the system.

 

Solution 1: Enter emergency mode and reset the password

Enter the power options of the virtual machine and select the option "Enter firmware when opening", so that you can enter the bios interface when starting the Linux system

blob.png

In the bios interface, set the CD-ROM to boot first when the system is booted

blob.png

Enter the Linux system installation wizard interface, select the Rescue installed system option to enter the wizard (press the Tab key to switch options)

blob.png

blob.png

blob.png

When configuring network card options, select NO to skip

blob.png

blob.png

 

Select to enter the bash shell environment, enter the chroot /mnt/sysimage command to switch to the root environment

blob.png

Enter the passwd root command to reset the password of the root user

blob.png

 

Enter the exit command to exit the root environment, and then enter the reboot command to restart the system to log in to the root account with the new password.

 

Solution 2: Boot into single-user mode, reset the password

Restart the host, and press the ↑↓ key when the GRUB menu appears to enter the wizard for modifying system startup parameters

blob.png

blob.png

blob.png

blob.png

 

After entering the shell environment in single-user mode, enter the passwd root command to reset the password of the root user

blob.png

 

Enter the reboot command to restart the system, and you can log in to the root account with the new password.

blob.png

blob.png

blob.png

 

In order to prevent others from stealing the root account by entering the single-user mode and resetting the password, we can restrict the GRUB menu

Use the password –md5 command to generate an MD5 encrypted password string

blob.png

 

Add a password string to the /boot/grub/grub.conf configuration file

blob.png

blob.png

 

The password setting position is before the first title, unauthorized modification of startup parameters is prohibited

blob.png

 

The password setting position is after the first title, and unauthorized access to the specified system is prohibited

blob.png

 

 Experiment complete

 


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325250883&siteId=291194637