Author Photo

Ahmer's SysAdmin Recipes is a blog for Linux System Administrators. This blog provides recipes for Installation & Configuration of Linux, Ubuntu, Oracle Database, MySQL, Apache, Nginx, Oracle Cloud Control, FreeIPA, Kerberos & OpenLDAP, Subversion, PXE, DevOps, etc. over Red Hat Enterprise Linux (RHEL), CentOS, Ubuntu and Windows.

Please give me your feedback and help me improve this blog. Please let me know If you want me to write on a specific topic.

Friday, 20 July 2018

Reset Root Password in RHEL 7

Reset Root Password in RHEL 7As we know that, the root is the superuser in Linux. We often come to situations, where, the root password is not available. Although it is trivial to reset root password, if you have a user with sudo rights, otherwise it becomes a little tricky.

In this post, I will demonstrate, how to reset the root password of a RHEL 7 Server.

To reset root password we must have physical access to the Server machine. Because we have to login into Emergency target.

emergency-target-cli-01

Once successfully reach at emergency target, follow the steps below to reset root password.

By default / filesystem is mounted at /sysroot with ro (read only) option in emergency target. We have to change it to rw (read write) mode, so we can change the files in our / filesystem.

emergency-target-mount-01

Now, we have our / filesystem in rw mode mounted at /sysroot. Now, we have to chroot to /sysroot directory, so we can execute commands and change files therein.

emergency-target-chroot-01

We have successfully chroot to our / filesystem. Let’s change root password using passwd command.

emergency-target-passwd-01

This file /.autorelabel is created to notify the SELinux to perform relabelling of all the files in the / filesystem. It is because the passwd command does not update the existing /etc/shadow file, instead it creates a copy and then update the password. Therefore, the newly created file does not has proper SELinux file contexts.

emergency-target-reboot-01

Now, Let the system boot with default settings. System start-up will take some more time as compare to regular boots because of the relabelling process.

multi-user-target-cli-01

Login with new password. We have successfully reset root password of our RHEL 7 server.

Reset Root Password in RHEL 7


YOU MIGHT ALSO LIKE:

No comments:

Post a Comment