Centos 7 Linux Forgot Password Solution- How to Change it

Here is the proper step by step guide to reset the forgotten password of CentOS 7 or 8 Linux systems. You can use the same for RedHat 7/8 as well.

If it is not stored in a certain file, it is easy to forget the login password for operations that are rarely used several times a week like logging in to the server.

Thus, What should you do if you forget the root password on the Linux system?

Reinstall the system? Naa, that is not the solution, instead, simply reset it without actually knowing or remembering the password.

The steps are as follows

  1. To recover or change the forgotten password of CentOS 7.0, first, reboot it. When you will get the grub menu,  press the “e” key
  2. Use the arrow key and go to the end of the screen where you will find the  line  rhg quiet and replace it with rd.break enforcing=0
  3. After that press ctrl+x to drop the current session into the scripting Shell.
  4. Now, mount Filesystem in “read and write” mode-  mount -o remount,rw /sysroot
  5. Use the command chroot /sysrootto access the system.
  6. Enter the command passwd root to reset the forgotten CentOS 7 password.
  7. Type exit to leave the sysroot.
  8. Make filesystem again read-only- mount -o remount,ro /sysroot
  9. Exit session and reboot the system. For that first type – exit and then reboot
  10. Now, you can log in to your system with the updated root password.
  11. After login, open the command terminal and run these two commands:
    sudo restorecon /etc/shadow
    sudo setenforce 1

To get a better idea see the screenshot for the above-given steps:

Edit grub menu

Recover CentOS 7 password Change boot Commands to change forget CentOS 7 Linux password

You can use the same method for CentOS 8 as well, however, here is the detailed article on resetting the CentOS 8 Linux password.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.