We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – How to reset root password on CentOS 7 / RHEL 7

Learn how to – How to reset root password on CentOS 7 / RHEL 7.

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.

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:

Cart

Your Cart is Empty

Back To Shop