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?

2 Answers 2

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.

6
  • Thanks for your answer, @taliezin. Both work for me. First method is also shown in documentation: red.ht/1vHVatu.
    – rzaaeeff
    Commented Mar 21, 2015 at 14:30
  • @taliezin what is the full meaning of rd in rd.break?
    – Learner
    Commented Apr 15, 2016 at 6:06
  • 1
    @SIslam, rd.break - drop to a shell at the end. More info you can find here.
    – taliezin
    Commented Apr 15, 2016 at 9:45
  • What does chroot /sysroot/ do?
    – Snowcrash
    Commented Feb 5, 2017 at 13:13
  • @SnowCrash, as rd.break asks for a break at an early stage of the boot process then after mounting as read/write you have to chroot to it, more info for chroot you can read here
    – taliezin
    Commented Feb 5, 2017 at 23:03
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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .