Question: How to reset root Password on CentOS 7 / RHEL 7?. I’ll take you through the steps to reset the forgotten root password on CentOS 7 / RHEL 7.

For RHEL 8 / CentOS 8, check: How to reset root password in RHEL 8

For you to be to able to reset the root password on CentOS 7 / RHEL 7 server, you need:

  • Working operating system – Only root password being unknown
  • A working GRUB boot loader

Note that CentOS 7 and RHEL 7 comes with GRUB version 2. It is not possible to reset root password in a single-user mode which was supported in RHEL 6.x and CentOS 6.x. The root password now operates in Single-User Mode and in emergency Mode.

How to reset root on CentOS 7 / RHEL 7

Use below steps to reset root password on your CentOS 7 / RHEL 7 server

Method 1: Reset root on CentOS 7 / RHEL 7

  1. Boot Up your system and on the Grub2 boot Menu screen, Press e on the Keyboard to enter.Grub Edit Mode
  2. After pressing “e“, scroll down to linux16 line and remove rhgb, quiet and LANG parameters. To easily move to the end of the line press ctrl+e and to move to the front of the line press ctrl+a. The Linux16 line will be linuxefi on the UEFI system.
  3. At the end of the linux16 line or linuxefi in case of UEFI system. Add the following line:rd.break Full line will be similar to:linux16 /vmlinuz-3.10.0-327.el7.x86_64 root=/dev/mapper/centos-root \ ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rd.break
  4. To boot the system with the New parameter parsed, press ctrl+x which will take you to prompt window.
  5. Mount the file system asread and write, you cannot change the password when the filesystem is not writable. Remount is as writable by typing the following command.
# mount -o remount,rw  /sysroot

7. Chroot into the /sysroot

# chroot /sysroot

8. Now change the password

# passwd
  • Replace password with the password you wish to use
    You can Learn How to Add New User To a Linux System Here

9. Set SELinux relabeling on next boot

# touch /.autorelabel

10. Resume the initialization and resume the System by

# exit
# exit

See below picture for illustration.

reset rhel 8 root password from grub 05

Method 2: Reset root on CentOS 7 / RHEL 7

1. An alternative method is to enable mount as rw. Your last line of linux16 contain:

rw init=/bin/bash

The full line will look like:

linux16 /vmlinuz-3.10.0-327.el7.x86_64 root=/dev/mapper/centos-root \
 ro rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rw init=/bin/bash

2. Press ctrl + x , you’ll be prompted with bash terminal window.

3. Now change the password

# passwd
  • Replace password with the password you wish to use

4. Set SELinux relabeling on next boot

# touch /.autorelabel

5. Resume reboot by typing exec /sbin/init to complete password reset.

# exec /sbin/init

You’ll now be able to login with your new password.

Recommended Video Courses to Learn Linux System Administration:

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!


As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.

2 COMMENTS

  1. When I go to change the password I get the error:
    the password fails the dictionary check – you are not registered in the password file

    and when i reboot and try to log in it says:
    User not known to the underlying authentication module.

    CentOS 7 (Core)
    Kernel 3.10.0-1160.31.1.el7.x86_64

LEAVE A REPLY

Please enter your comment!
Please enter your name here