• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL 7 : How to Reset root password

by admin

Resetting root password in CentOS/RHEL 7 is slightly different than the older versions. The post describes the procedure to reset the lost root password.

Reboot and edit grub2

Reboot the system and press any key to stop the auto-boot from the default kernel. Press “e” after selecting the kernel line.

grub menu rhel 7

Append rd.break to kernel

When you are in edit mode, go to the line starting with linux16 and append rd.break to the end of this line.

add rd.break to grub menu rhel 7

This will cause the machine to boot into emergency mode, which gives you root user privileges without you having to enter a root user password. Even if the root user password hasn’t been set, this still works.

Reboot the system

Press CTLR+x after appending the rd.break to the kernel. This will reboot the system into emergency mode.

enter into emergency mode rhel 7

Remount sysroot

First we will remount the sysroot file system in read write mode and then use chroot to got into a chroot jail:

# mount -o remount,rw /sysroot
# chroot /sysroot

Reset root password

Finally, type passwd command in the command line and set the new password for root user. You might get some warnings like “password fails dictionary check” if your password is weak. You may safely ignore the warning and set the password you want.

# passwd

changing the root password rhel 7

SElinux relabeling

Make sure that all unlabeled files ( including shadow file ) gets relabeled during booting. Touching the hidden file autorelabel instructs SElinux to relabel the files changed outside of its regular context, like the file /etc/shadow.

# touch /.autorelabel

sync

To flush all cache to disk, type the command:

# sync

Reboot

Type twice the exit command to leave the chroot environment and log out. The system will apply some SELinux contexts and reboot. You can now log in using your newly set root password.

Filed Under: CentOS/RHEL 7

Some more articles you might also be interested in …

  1. OpenLDAP Server and Client Utilities list
  2. CentOS / RHEL 7 : How to sync chrony to local clock
  3. CentOS / RHEL : How to restore/recover a deleted volume group in LVM
  4. How to Back Up and Restore XFS File Systems (xfsdump / xfsrestore)
  5. How to Change the filesystem Labels in CentOS/RHEL
  6. How to Mount Guest Qcow2 Virtual disk Image containing LVM on KVM Host Machine
  7. “lsb_release: command not found” – Fix in CentOS/RHEL
  8. How to change the default location (/var/cache/yum) of yum cache
  9. SSH Login Stuck At : “debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP” CentOS/RHEL 7
  10. Allow cronjobs to run by pam even if user password is expired

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright