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
In the bios interface, set the CD-ROM to boot first when the system is booted
Enter the Linux system installation wizard interface, select the Rescue installed system option to enter the wizard (press the Tab key to switch options)
When configuring network card options, select NO to skip
Select to enter the bash shell environment, enter the chroot /mnt/sysimage command to switch to the root environment
Enter the passwd root command to reset the password of the root user
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
After entering the shell environment in single-user mode, enter the passwd root command to reset the password of the root user
Enter the reboot command to restart the system, and you can log in to the root account with the new password.
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
Add a password string to the /boot/grub/grub.conf configuration file
The password setting position is before the first title, unauthorized modification of startup parameters is prohibited
The password setting position is after the first title, and unauthorized access to the specified system is prohibited
Experiment complete