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:
- Grub > e
init=/bin/sh(Removerhgbandquiettags if necessary) > Ctrl+x/usr/sbin/load_policy -imount -o remount,rw /passwd rootorpasswdmount -o remount,ro /
B method:
- Grub > e
rd.break> Ctrl+xmount -o remount,rw /sysroot/chroot /sysroot/passwd rootorpasswdtouch /.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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
-
For RHEL5, RHEL6, append
1,sorinit=/bin/bashto kernel cmdline -
For RHEL7, RHEL8, CentOS7, CentOS8, append
rd.breakorinit=/bin/bashto 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.
Method 2
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)
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0