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

The Geek Diary

CONCEPTS | BASICS | HOWTO

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

CentOS / RHEL 7 : How to recover from deleted root entry in /etc/shadow and/or /etc/passwd files

By admin

The Problem

The ‘root’ entry was removed from /etc/shadow and /etc/passwd. How to recover the deleted root user entry.

Solution

To be able to recover the deleted root user entry from /etc/shadow and /etc/passwd file, we need to boot the system into single user mode. Follow the steps below to boot the system into single user mode and recover the deleted root user entry.

Booting the system into single user mode

1. Boot the system and press [e] at the Grub Kernel selection whilst highlighting a working Kernel.

select kernel RHEL 7 recover root entry in :etc:shadow file

2. Scroll down to the linux16 line, goto the end of the line and type rd.break.

add rd.break to boot into single user modde RHEL 7

3. Press CTRL+X to boot with the modified options.

4. At the switch_root prompt, remount the system’s root as writable and then switch to it:

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

switch_root prompt recover root entry in passwd file

Recovering the deleted root entry

Once you have booted into the single user mode follow the steps given below to recover the deleted root entry.

1. Add the root entry back into /etc/passwd file. Below shown is the most commonly used attributes of the user root.

# vi /etc/passwd
root:x:0:0:root:/root:/bin/bash

2. Similarly, add the root entry back into /etc/shadow file.

# vi /etc/shadow
root:*::0:99999:7:::

3. Re-create your root password using the passwd command.

# passwd

4. If SELinux is enabled, force a filesystem relabel on reboot by creating the file .autorelabel in the / directory.

# touch /.autorelabel

5. As a final step reboot the server and verify if you can login into the server using the user root.

# reboot
How to recover from deleted root entry in /etc/shadow and/or /etc/passwd files in CentOS / RHEL 6

Filed Under: CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. How to change the PATH variable in Linux
  2. How systemd-tmpfiles cleans up /tmp/ or /var/tmp (replacement of tmpwatch) in CentOS / RHEL 7
  3. How to Add a 3rd Disk to Create a 3-way Mirror RAID1 MD Device (CentOS/RHEL 7)
  4. How to configure resource groups for MySQL Server running on Linux
  5. How to remove the multipath device after unmapping the storage LUN from server
  6. How to Remove a Dead Mulitpath Device without Reboot in CentOS/RHEL
  7. How to run rsyslog as a non-root user in CentOS/RHEL 7
  8. Getting “parsing errors” When Running ‘yum repolist’
  9. Beginners Guide to “journalctl” – How To Use Journalctl to View and Manipulate Systemd Logs
  10. How to Configure Interface bonding (NIC Teaming) on Oracle Linux 6

You May Also Like

Primary Sidebar

Recent Posts

  • How to Configure Automatic Package Updates on the Server in CentOS/RHEL 8
  • FATAL: Error inserting rds_rdma
  • Failed to start LSB: Bring up/down networking – On restarting network service CentOS/RHEL (DHCP client)
  • How To Add Timestamps To dmesg Kernel Boot Log in CentOS/RHEL
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary