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.
Read Also: How to Set Up Automatic Updates for CentOS 8 and How to Reset Forgotten Root Password in RHEL 8
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 ro
with rw
and append an extra kernel parameter init=/sysroot/bin/sh
. In a nutshell, simply replace the kernel parameter ro
with rw init=/sysroot/bin/sh
.
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.
Worked perfectly. Threw me off for a second as I didn’t realize we were CHOOSING user: root. Plus how it doesn’t show your output when typing the password and then confirming the password. I got it the second time around though xD
Thanks. This was really cool. You are a true Hat!
Hello, I have many OS installed, Ubuntu 20.04 is the grub boot loader, I cannot reset the CentOS8 root password because it doesn’t work. Any ideas?
I have just tried this, but when I get to the
# chroot /sysroot
step, I am being told: “chroot: failed to run the command ‘/bin/sh’: No such file or directory”.Please can you help me?
Thanks, Joe
After done this process it is not working it shows me
[FAILED] Failed to start user manager for UID 42.
see ‘systemctl status [email protected]‘ for details
Then what should i do?
did you find a solution for this? I also have the same issue.
Hi
The Process was done successfully, but now it keeps on rebooting a lot after autorelabel log, is it suppose to do like that?
Hey Tebogo, It shouldn’t keep on rebooting. Kindly check your configuration once again and ensure you follow the guide carefully. Also, you can paste your configuration so that I can diagnose what’s wrong.
Hi,
Very useful Article for me.
Thanks a lot
Thank you. I’m glad you found it useful.
Thank you!
Is there any difference in resetting the root password between Centos and Red Hat?
Are you planning to write a similar article about Debian/Ubuntu?
Hey Alexey, There is a subtle difference in RHEL 8, but the procedure is largely similar. I’m putting up a post on RHEL 8 and Linux Mint as well within the course of this week and next week.
Hi James,
Thank you, I’m waiting for your new articles )))
You’re welcome and keep it Tecmint !
This is the functional equivalent of using
rd.break
?Hey David, yes it is. A similar article on how to do it on RHEL 8 is scheduled within the course of the week.
This is the correct way: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_basic_system_settings/managing-users-groups-permissions_configuring-basic-system-settings#resetting-forgotten-root-password-on-boot_changing-and-resetting-the-root-password
You have to break the boot process with
rd.break
.Hey Gnu, This is a guide on resetting a forgotten password on CentOS 8. A guide for RHEL 8 is coming up before the week comes to an end.