Share on Social Media

In this tutorial, you will learn, how to reset Root Password in CentOS 7 or other Red hat based Linux servers. #centlinux #linux #recovery

Problem Statement:

As 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 root password in CentOS 7.

Read Also: How to reset Root Password in CentOS 6

Reset Root Password in CentOS 7:

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


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.


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.


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


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.


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.


Login with new password.


We have successfully reset root password in CentOS 7.

Leave a Reply

Your email address will not be published. Required fields are marked *