Red Hat Enterprise Linux




Chapters     |     Exercises     |     Workshop     |    

Resetting the Root Password

A common scenario for a Linux administrator is that the root password has gone missing. If that happens, you need to reset it. The only way to do that is by booting into minimal mode, which allows you to log in without entering a password. To do so, follow these steps:

1. On system boot, press e when the GRUB 2 boot menu is shown.

2. Enter rd.break as boot argument to the line that loads the kernel and press Ctrl+X to boot with this option.

3. You’ll now be dropped at the end of the boot stage where initramfs is loaded, just before a mount of the root file system on the directory /.

4. Type mount -o remount,rw /sysroot to get read/write access to the system image.

5. At this point, make the contents of the /sysimage directory your new root directory by typing chroot /sysroot .

6. Now you can enter passwd and set the new password for the user root.

7. Because at this very early boot stage SELinux has not been activated yet, the context type on /etc/shadow will be messed up. If you reboot at this point, no one will be able to log in. So you must make sure that the context type is set correctly. To do this, at this point you should load the SELinux policy by using load_policy -i .

8. Now you can manually set the correct context type to /etc/shadow. To do this, type chcon -t shadow_t /etc/shadow .

9. Reboot. You can now log in with the changed password for user root. systemctl reboot


Eninam BAGNABANA     |         |     bagnadavid@outlook.fr     |