How to recover root password

I know to recover the root password with RHEL 7 and 8, and CentOS 7 and 8, but when I attempt to remount or chroot to /sysroot that does not seem to work on Rocky Linux 8.

Can someone provide the official instructions for recovering the root password for this brand?

Thanks.

I reset mine perfectly fine with this method:

  1. Reboot server, at grub screen press e to edit.
  2. Go to end of the linux line and add rd.break
  3. Do CTRL-X to boot.
  4. Do mount -o remount,rw /sysroot
  5. Do chroot /sysroot
  6. Do passwd root
  7. Do touch /.autorelabel
  8. Do exit

Now reboot, and you should be able to login with the new root password. The command in point 7 is required for selinux, else it won’t work. This will then relabel all files that would have had their selinux permissions reset after the commands we just ran. If selinux is disabled on your system this probably can be omitted, but recommend running it anway.

Thanks, I had tried these steps, so I am guessing that when I renamed one of the libraries (for a video I was going to make and share) I must have broken the OS. :frowning:

Thanks @iwalker !

@iwalker , can I also recover my root password if I have the media in the “drive” considering this is a VM in reality?

Not sure to be honest. Maybe it’s possible to do it like that, by chrooting after booting from the media and following the remaining steps.

I tried that, but could not find /mnt/sysroot.

Hi. I tried the rd.break, but I still get prompted for the root password.

stlanlo45,

It asked me for the password when I selected normal, versioned kernels in grub. When I select the kernel option with “rescue” in the name, the steps above worked for me.

image

Thanks for the update. It worked for me.

works for me
but I add setenforce=0 after rd.break .

  1. Reboot server, at grub screen press e to edit.
  2. Go to end of the linux line and add rd.break setenforce=0
  3. Do CTRL-X to boot.
  4. Do mount -o remount,rw /sysroot
  5. Do chroot /sysroot
  6. Do passwd root
  7. Do touch /.autorelabel
  8. Do exit
  9. Do exit

tip - > maybe reboot take several time, continue awaiting

Hey mate, I created an account on this forum just to say THANK YOU!!

I was tearing my hair out trying to figure out why I wasn’t able to log into the root account after resetting it, and this method worked a charm! I was trying all the other methods for CentOS and nothing was working, but this was the golden forum post that saved me.

You’re a legend mate.

Cheers,
BFG

Hi. Thanks. It worked for me but now I can login only as root. Every time I see “Give root password for maintenance” than login as root but when I try sudo --user=me /bin/bash and startx I see “Permission denied” to console (Xf…). How can I return normal login procedure?

Using rd.break takes me to emergency mode instead of to the unmounted shell

This is the look of the grub edit menu

I do remove the “rhgb quiet” and add “rd.break”, as every guide will suggest. Idk if the “crashkernel” option is what indicates that it goes to emergency mode, or not, but I imagined it would help clarify the situation a little.

It is a VM, Rocky Linux 10.2 (Red Quartz)

Hi,

Just tested and yes I get emergency mode. But I am still able to perform:-

mount -o remount,rw /sysroot
chroot /sysroot

So you should still be able to reset the root password.

Regards Tom.

Haven’t tried it in a while, but adding “init=/bin/bash” to the kernel command line should give you a root prompt. You have to do a remount,rw on / before running passwd.

It does work using “init=/bin/bash”, thank you very much, but I make a point to respond with a presumed issue regardless, in case eithe I’m mistaken in my understanding, in which case it’d be useful for someone else a bit daft like me, or that there really is something strange happening

I am still prompted for the root password. Without adding “init=/bin/bash” to the linux line after pressing Control-D to continue it just boots to the OS normally, but adding it I do go to a bash-5.2 shell

EDIT: I’d also like to apologize for the late reply

Usually it was enough to just add rd.break to the end of the line. However, I believe it doesn’t always work, and sometimes you have to try systemd.unit=emergency.target which should then allow it to boot to the console, and then allow you to mount your partitions and chroot into it.