How To Break/Crack/Reset Root Login Password On CentOS/RHEL 7?
Originally published at https://kapendra.com.
Linux system is known for its security features and if you forget your password then is really the pain ass. You have locked out the system and can not perform any administrative tasks. Breaking cracking or recovering passwords in CentOS 7 / RHEL 7 is similar to that of doing the same in version 6 but, the introduction of SELinux and systemd
have given you some changes. Well here is the key to Break/Crack/Reset Root Login in CentOS/RHEL 7.
Scenario: My Server IP is 192.168.1.188
Note: If you are a SUDO user then prefix every command with sudo, like #sudo ifconfig
Step 1: Get And Edit GRUB2 Boot Menu
First, we will restart the machine with CTRL+ALT+DEL and once you prompted for the grub boot menu select your kernel version using the up and down arrow and press ‘e’ to pass some option/argument into the kernel.
Step 2: Pass Agreement and CTRL+X
Now after performing step 1 you will kernel code like structure. so move to last using the arrow key (or CTRL+E)and find the line starting with linux16 and press the END button and start deleting till ‘ro’ like shown in the image.
after deleting shown lines append(write) rd.break
with space after ro
like this below image
once you edit the boot line and passed your argument(rd.break
) press CTRL+X
to get this reboot in single-mode
Step 3: Remounting Root Partition (READ/WRITE)
After the second step, your system will restart and will drop you to a shell in single mode. Here we will remount the file system and make it as root with the following command
# mount -o remount,rw /sysroot
you can confirm that you are in Read/Write
state by using the command.
#mount | grep root
You should see the result like below
Step 4: Change Password and chroot
After getting the system into R/W mode you need to change the root of the system and then you may change the password as below.
#chroot /sysroot
#passwd
with the above command, you can change the password of any user along with the root.
Step 5: SELinux AutoRelabeling
The relabeling of SELinux is a very much important thing to do in CentOS/RHEL 7 system because there the SELinux enables and if you missed this step you will not be able to log in with your new password which you got reset in the previous step. The following command will change and relabeled the SELinux context in the entire system after the reboot
#touch /.autorelabel
Step 6: Reboot System
We have successfully cracked or OS password now we need to get this system reboot with the following command
# exec /sbin/init
Conclusion: Though Linux is known as a more secure OS and this knowledge of breaking passwords can help you in many situations.
Originally published at https://kapendra.com.