9

I know several ways to reset root user's password, but want to know which is the best and why it is. For example:

A method:

  1. Grub > e
  2. init=/bin/sh (Remove rhgb and quiet tags if necessary) > Ctrl+x
  3. /usr/sbin/load_policy -i
  4. mount -o remount,rw /
  5. passwd root or passwd
  6. mount -o remount,ro /


B method:

  1. Grub > e
  2. rd.break > Ctrl+x
  3. mount -o remount,rw /sysroot/
  4. chroot /sysroot/
  5. passwd root or passwd
  6. touch /.autorelabel

Which is the best? Why is it best? I'm preparing for RHCSA (Red Hat Certified System Admin) exam. I need to know the relative merits of each approach. Is one of them more portable? Safer? Is there a reason to choose one over the other?

αғsнιη
  • 41,407
rzaaeeff
  • 532

2 Answers2

6

I think the best way is as is shown in Red Hat documentation.
This is your second method. For GRUB2/RHEL7 single/emergency mode should not work since it will use sulogin to authenticate you before presenting the command prompt.

So lets mark off different methods.

  1. For RHEL5, RHEL6, append 1, s or init=/bin/bash to kernel cmdline

  2. For RHEL7, RHEL8, CentOS7, CentOS8, append rd.break or init=/bin/bash to kernel cmdline

It appears that the second method is not available on RHEL5 and RHEL6. But for RHEL7 I will prefer the first because adding init=/bin/bash is a bit tricky when single mode is password protected and may be appending rd.break is a way to standardize it.

αғsнιη
  • 41,407
taliezin
  • 9,275
4

The ‘rd’ part of ‘rd.break’ refers to ramdisk— the initial ramdisk (initrd) environment.

The second method (using rd.break) is preferable for RHEL7. Some systems (with a USB keyboard or a VM) don’t actually seem to set the password when you reboot. Possibly it’s only setting the password for /etc/shadow inside the ramdisk, and not the one you were expecting.

What that has to do with a USB keyboard I don’t know, but that’s what the knowledge base arrival says, and what my experience to date has been. I rather suspect this has more to do with whether your root filesystem is on LVM (hint: dracut)