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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • 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. rc-update Command Examples in Linux
  2. How to Use Iperf to Test Network Performance in Linux
  3. dmidecode Command Examples in Linux
  4. Downgrading an rpm package to a lower version (using “rpm” command)
  5. fscrypt: command not found
  6. scp: command not found
  7. usermod: command not found
  8. lsattr: command not found
  9. caja Command Examples in Linux
  10. How the BASH Shell load its configuration files in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • gml2gv Command Examples
  • glow Command Examples
  • glib-compile-resources Command Examples
  • glances Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright