• 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

How to Reset Root Password in CentOS/RHEL 8

by admin

Starting from CentOS/RHEL 7, resetting of root password has slightly changed than its earlier versions. Let see in this post how we can recover a lost root password on a CentOS/RHEL 8 machine.

Breaking Boot Sequence

1. Reboot the system and interrupt the boot loader sequence by pressing any key.

2. Move the cursor to the entry that needs to be booted.

reset root password RHEL 8

3. Press e to edit the selected entry. Move the cursor to the kernel command line (the line that starts with linux, it looks like the below output:

reset root password CentOS 8

4. Append rd.break options in the end of the kernel command line. This will break just before control is handed from the initramfs to the actual system.

append rd.break reset root password RHEL 8

5. Press “Ctrl+x” and reboot the system. At this point, a root shell will be presented, with the root file system for the actual system mounted read-only on /sysroot.

recover root password RHEL 8

Resetting root Password

To recover the root password from this point, use the following procedure.

1. Verify if the the root filesystem is mounted as read-only at the ‘/sysroot’ directory:

switch_root:/# mount | grep -i sysroot

recover root password CentOS 8

2. Remount /sysroot as read-write:

switch_root:/# mount -o remount,rw /sysroot

3. Switch into a chroot jail, where /sysroot is treated as the root of the file system tree:

switch_root:/# chroot /sysroot
sh-4.4# 

4. Set a new root password here:

# passwd root

reset root password CentOS:RHEL 8

You can ignore the warning here for the less complicated password.

Rebel SELinux

SELinux is not yet enabled at this point, so any new files being created will not have an SELinux context assigned to them. Keep in mind that some tools (such as passwd) first create a new file, then move it in place of the file they are intended to edit, effectively creating a new file without an SELinux context

1. Make sure that all unlabeled files (including /etc/shadow at this point) get relabeled during boot.

sh-4.2# touch /.autorelabel

2. Type exit twice. The first will exit the chroot jail, and the second will exit the initramfs debug shell. At this point, the system will continue booting, perform a full SELinux relabel, then reboot again.

exit twice reset root password RHEL 8

CentOS / RHEL 7 : How to Reset root password

Filed Under: CentOS/RHEL 8, Linux

Some more articles you might also be interested in …

  1. tshark Command Examples in Linux
  2. Difference between soft links and hard links in Linux
  3. How to Use iptables instead of firewalld on CentOS/RHEL 7 and 8
  4. ifrename Command Examples in Linux
  5. Error “530: permission denied” when user logs in to vsftpd server via ftp
  6. jlink: command not found
  7. echo Command Examples in Linux
  8. Understanding rsyslog Actions
  9. How To Configure SNMP Daemons: snmpd and snmptrapd on CentOS/RHEL 5,6 and 7
  10. lvs: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • aws ec2: CLI for AWS EC2 (Command Examples)
  • aws cur – Create, query, and delete AWS usage report definitions (Command Examples)
  • aws configure – Manage configuration for the AWS CLI (Command Examples)
  • aws cognito-idp: Manage Amazon Cognito user pool and its users and groups using the CLI

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright