How to deal with forgetting the root password after installing a Linux virtual machine in VMware

OS version: Red Hat 7.7

Problem statement:

I installed a Linux virtual machine with VMWare before, but I forgot the root password because it has not been used for a long time. So you need to change the root password.

Root password modification

The operation steps for changing the root password are recorded as follows.

1. Start the virtual machine, and when the startup countdown interface appears, press any key on the keyboard to enter the following interface:

insert image description here

2. Then press the "E" key on the keyboard and press the e key on the keyboard to enter the edit mode:
(Note: Select the first option (highlighted is selected))

crashkernelChange the previous ro to rw (ro means readonly permission), and add init=/bin/sh
insert image description here
after the modification is completed, Ctrl+x to save

3. Then it will enter the safe mode:
enter the passwd command to change the password, and follow the prompts to change the root password. After entering the password and confirming the password, the change can be successful.

If you enter the passwd command for the first time and you are prompted that the command cannot be found, enter the chroot /sysroot command and then enter the passwd command again.

4. Run the touch /.autorelabel command to make the modified password take effect.
After the touch /.autorelabel command is executed, execute the exit command to exit, and then the reboot command to restart the Linux service of the virtual machine. After the successful restart, you can log in with the new password.
insert image description here
Screenshot of the restart process:
insert image description here


Reference:
https://blog.csdn.net/smilehappiness/article/details/105306049
https://www.cnblogs.com/limingli/p/10032690.html

Guess you like

Origin blog.csdn.net/Ruishine/article/details/129048890