Hamsa K
Editor
3 min read | 6 months ago

How to Reset Lost Root Password in Centos 8

Reset Forgotten root password in centos 8

It is easy to reset your root password if you have an active user account with sudo privileges.then use below command.But what if you don’t have access to a local user with sudo privileges then you need to follow below process to change root password.

Step 1: Reboot the server

Step 2: interrupt boot menu

once you see grub menu, select the kernel version you want to boot server and press 'e' 

step 3: Edit kernel boot parameters

We will modify these options so as to reset the root password. The default parameters configured looks like below.

 you can find the kernel parameter ro and change ro to rw and add an extra parameter init=/sysroot/bin/sh with space-separated as shown below.Don't forget to keep space between rw and 'init'.

once parameters has been changed press ctrl+x to enter into emergency mode means single use mode.

Now you will be in shell promt,mount root file system with chroot command.

chroot /sysroot

then reset root password with below command

passwd

once you changed password of root user, update Selinux as below

touch /.autorelabel
then exit from chroot and reboot the server
exit
reboot

then it wil take few mins to complete for selinux relabeling 

now you can login your system with new password.

 



Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy