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
Table of Contents
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.
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
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
Over here, we will check the status of whether the system is “ro” or “rw” to check this pass command.
# mount | grep sysroot
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
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
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}
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
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
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
Now login to your system with the new password, That’s it for to break or reset password in CentOS/RHEL8.
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
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.
Innovative tech mind with 12 years of experience working as a computer programmer, web developer, and security researcher. Capable of working with a variety of technology and software solutions, and managing databases.
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.