Due to improper work handover, inadequate information recording, forgotten passwords, etc., sometimes the root administrator password is lost. At this time, we need to manually crack the root password. So what should we do? Next, let's take a look at the method to crack the password on CentOS 7
First, we power on the host normally, and when the system is booted to the boot menu item, immediately press any key to pause the startup (the system defaults to 5 seconds, if the first time is missed, restart and try again), then press e Key to enter edit mode, as shown in the figure
Move the cursor to the line starting with linux16, add the kernel parameter rd.break
(preceding a space to inform grub2 that this is an independent command item) after the quiet item at the end, and then press the Ctrl + X
key combination to start
After the bootloader reads the above kernel parameters, it will enter the following interface
As we know, when entering Recure Mode
and Emergency Mode
, the root system entered by default is a pseudo-root, and the root directory needs to be switched, so we pass mount
Command first look at the current mounting situation
As we can see in the above picture, our system partition /dev/sda3
is mounted on /sysroot
, so we need /dev/sda3
to partition the real system (ie /dev/sda3
) Mount to /sysroot
in read-write mode (rw)
mount –o remount,rw /sysroot
We use mount
to confirm whether it has been remounted in read-write mode
As above, you can confirm that it has been successfully mounted.
Cut the roots. ***Attention, the shell prompt changes at this time. ***
chroot /sysroot
Reset the root password and perform the marking operation (ie SELinux security label), and the system may restart twice to complete the marking work.
After the marking is completed, enter exit
twice in a row, then reboot
, and you can enter the login interface after restarting.
***At this point, the root password under CentOS 7 has been successfully reset, and relevant management work can be done later. In particular, here is an additional method to crack the root password. The overall idea is the same as the above method. The main difference lies in the shell used for the recovery operation. ***
Same as method 1, boot and press the e
key to enter the boot menu item of grub2, and edit the kernel command parameters. Add rw init=/sysroot/bin/sh
at the end of the line starting with linux16, and then press Ctrl + X
to start. Please note that when modifying the kernel command chain, this method directly declares the mount in read-write mode rw, so you can directly cut the root operation after restarting
Same as method 1, follow by cut root chroot -> reset root password -> hit the security label -> exit -> reboot
Recommended Posts