• 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 recover from deleted root entry in /etc/shadow and/or /etc/passwd files in CentOS / RHEL 6

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 post below to boot the system into single user mode.

CentOS / RHEL 6 : How to Boot into single user mode

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
CentOS / RHEL 7 : How to recover from deleted root entry in /etc/shadow and/or /etc/passwd files

Filed Under: CentOS/RHEL 6, Linux

Some more articles you might also be interested in …

  1. How to Change Timezone from CST To EST in CentOS/RHEL 7 Server
  2. How to extend ASM disk from OS level in CentOS/RHEL
  3. ack – A search tool like grep, optimized for developers (Command Examples)
  4. mke2fs Command Examples in Linux
  5. ‘error opening class fc_host’ – systool Command Error on CentOS/RHEL 7 and 8
  6. Unable to Start RDMA Services on CentOS/RHEL 7
  7. i3lock: command not found
  8. How to Check the Size of the Yum Channels in Oracle Linux
  9. touch: command not found
  10. yum Command Examples in Linux

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