How to Reset Forgotten Root Password in CentOS 8
It’s not uncommon for users to forget their root password. This happens especially if you haven’t logged in as the root user for long periods of time. In this brief guide, we will walk through the steps of resetting a forgotten root password in CentOS 8 Linux.
Let’s get started…
Reset Forgotten root Password in CentOS 8
First, reboot or power on your CentOS 8 system. Select the kernel you want to boot into. Next, press
‘e’ on the keyboard to interrupt the boot process and make changes.
On the next screen, locate the
ro (read-only) kernel parameter as highlighted below.
Replace the kernel parameter
rw and append an extra kernel parameter
init=/sysroot/bin/sh. In a nutshell, simply replace the kernel parameter
Once done with making the changes, hit
Ctrl + X combination on the keyboard to enter single-user mode.
Next, run the command below to mount the root file system in read and write mode.
:/# chroot /sysroot
You can now change the root password by executing the command:
:/# passwd root
Provide a new root password and confirm it. For best practice select a password with a combination of uppercase, lowercase, numerical and special characters to boost password strength.
Next, run the command below to enable SELinux relabelling.
:/# touch /.autorelabel
To apply the changes, exit and reboot the CentOS 8 system.
:/# exit :/# reboot
Upon reboot, the SELinux relabelling process will commence. Give it about 3 minutes.
When the relabelling process is done, the system will reboot and thereafter, you will be presented with a logon screen upon which you can now log in as the root user with the new password that you just set.
We hope this tutorial will be beneficial to you. Feel free to weigh in your feedback if you are stuck.