How to reset or crack the password in CentOS/RHEL?

It is normal to forget passwords this day because we have made so many accounts worldwide and local.

If you have access to the root password, it is easy to change the local user password, but you forget the root password, then you will not change it.

We will show you the methods to crack or reset password in CentOS8/RHEL

How to reset password in CentOS8/RHEL?

Step 1: Boot / reboot CentOS8

First of all, restart or boot your system and wait for the grub to load and interrupt the boot pressing using the arrow key.

Then Press “e” from your keyboard to the selected version.

reset password in centos/rhel

Step 2: Where to Append rd.break

As you pressed the “e” from the keyboard new screen will open. Over here, you will see the kernel boot parameters.

You need to append “rd.break” this will interrupt the boot process before the control is passed to the kernel.

To modify parameters, go to the line “linux” and after “rhgb quiet” add line “rd.break.”

Before proceeding ahead check the below image

After appending now start the process to boot pressing key “Ctrl – x”

# rd.break
Interrupt boot process
Interrupt boot process

Step 3: How to Open Shell

When you pressed the “Ctrl – x,” this will boot your system into the shell. Over here you need to pass the command to reset the password

reset password in centos/rhel Open Shell
Open Shell

Over here, we will check the status of whether the system is “ro” or “rw” to check this pass command.

# mount | grep sysroot
Check rw permissions
Check rw permissions

On the next step will change “ro” to “rw” and we will reset the password.

Step 4: How to Modify Password

Above you have checked the system is “ro” read-only now we have to modify the system to “rw” read and write for this pass command

# mount -o remount,rw /sysroot
Mount sysroot as read & write
Mount sysroot as read & write

Now the system is mounted with the read and write permission. In this step, we will change the root directory to the /sysroot.

To do this we need to type command

# chroot /sysroot
Change root directory
Change root directory

In this step, we will change the password of the desired user or root user. To perform this, we need to type a command.

# passwd {username}
Enter new password
Enter new password

If you want to change your root account password, pass the command “passwd,” or If you want to change the password of any specific user, then pass the username along passwd like “passwd centos.”

Password is updated successfully now also you can reboot your system into normal mode, but CentOS/RHEL8 by default use SELinux enforcing mode because of that you have to face problem to restart your system

To prevent this, we will create a new file that we will call “autorelable” to create a file pass command.

Read this: – How to install the official Snap Store on Ubuntu, Arch, Manjaro, CentOS, Fedora

# touch /.autorelabel
reset password in centos/rhel Make a hidden file
Make a hidden file

You are thinking about why we have created a hidden autorelabel? The reason behind this is when we reset the password, that a time shadow file (/etc/shadow) is modified with an incorrect SELinux context.

Now, what command “touch /.autorelabel” will create a hidden file under the root directory with the name .autorelabel

When we boot into the system SELinux subsystem, we will detect this file and the relabeling of the files on that system with the correct SELinux context. This process takes time to complete. It depends upon the size of the Hard Disk

Your command will look like this image

Complete steps to reset password
Complete steps to reset password

This is the last step you need to pass the “exit” command twice to get out from 1st exit will exit from the chroot environment and the second exit from the root shell, then wait for the relabel process to complete.

# exit
# exit
reset password in centos/rhel relabel process
relabel process

Now login to your system with the new password, That’s it for to break or reset password in CentOS/RHEL8.

reset password in centos/rhel
Now login with updated password
Now login with updated password

The difficulty you may face

First of all, follow the steps in sequence to avoid any error. Then also, if you see the error [FAILED] Failed to start Crash recovery kernel arming.

It means you have missed to make a new file, “.autorelabel.”So, you need to repeat the process and make file passing command

#touch /.autorelabel
reset password in centos/rhel Error while boot
Error while boot

Wrap up

This is an easy and simple way to reset passwords in CentOS/RHEL 8. Make sure to follow step by step to avoid any errors.

Please let us know how much this guide helps you to understand. If you want me to cover any specific topic, then let me know.

This Post Has One Comment

  1. Zaid

    It’s a great pleasure reading your post. It’s full of information I am looking for and I love to post a comment that “The content of your post is awesome” Good work.

Leave a Reply