• 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 : How to Recover from deleted /etc/passwd file

By admin

So, on one fine day you found that the /etc/passwd file is missing from your linux system. You are not able to login into the system because of this and Upon rebooting into single-mode mode the /etc/passwd file was found to be empty – no account information available. Do not worry, its not the end of the world. You can still recover it. Follow the steps below to recover a deleted /etc/passwd file in RHEL system.

Purpose of /etc/passwd- file

While adding or modifying a user, the original /ect/passwd file will be saved as /etc/passwd-.
This functionality is same with /etc/shadow, /etc/gshadow and /etc/group files. When these files are changed, the old file will be saved ending with a dash “–“.

Recovering deleted /etc/passwd file

1. Boot into single mode.

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

2. Remount root file system in read/write mode:

# mount -o rw,remount /

3. Locate the /etc/passwd- file.

# ls -lah /etc/passwd-
-rw-------  1  root  root  2.4K  May  15 15:46       /etc/passwd-

3. Copy the file /etc/passwd- to the file /etc/passwd.

# cp /etc/passwd- /etc/passwd
Note : Make sure you manually check the backup file /etc/passwd-. Check for userids, home directories etc.

4. Use the pwconv command to create /etc/shadow file from the /etc/passwd file.

# pwconv

5. Use the passwd command to reset the root password.

# passwd root

6. Reboot normally and verify successful login.

# shutdown -r now

Filed Under: Linux

Some more articles you might also be interested in …

  1. CentOS / RHEL : Converting an Existing Root Filesystem to LVM Partition
  2. How to install and configure sosreport under CentOS / RHEL
  3. How to Ignore/Disable Specific auditd Logging Entries
  4. Linux Interview Questions – Basic File and Directory Permissions
  5. CentOS / RHEL 6 : How to force a NTP sync with the NTP server(s)
  6. Linux OS Service ‘NetworkManagerDispatcher’
  7. Status Commands in Linux – date, ps, who, uptime, finger, rup, ruser
  8. Understanding How an Email System Works
  9. Sample /etc/mke2fs.conf file
  10. How To Create a Partition Using “parted” Command

You May Also Like

Primary Sidebar

Recent Posts

  • How to Disable IPv6 on Ubuntu 18.04 Bionic Beaver Linux
  • How to Capture More Logs in /var/log/dmesg for CentOS/RHEL
  • Unable to Start RDMA Services on CentOS/RHEL 7
  • How to rename a KVM VM with virsh
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary