Repair /etc/passwd and /etc/group

By | 2010/06/27

How can I repair /etc/passwd and /etc/group?

Migrating or editing Linux users can be frustrating. On Redhat or CentOS you may see this when running system-config-users:

“The user database cannot be read. This problem is most likely caused by a mismatch in /etc/passwd and /etc/shadow. The program will now exit.”

Eek! So something is not right. Try these commands which *may* solve your problem.


This will check for duplicates and errors in /etc/passwd and /etc/shadow:

pwck

This will check for duplicates and errors in /etc/group and /etc/gshadow:

grpck


Here is an example output:

[user@server ~]$ sudo pwck
user adm: directory /var/adm does not exist
user uucp: directory /var/spool/uucp does not exist
user games: no group 100
user gopher: directory /var/gopher does not exist
user pcap: directory /var/arpwatch does not exist
user avahi-autoipd: directory /var/lib/avahi-autoipd does not exist
user asdf: directory /home/asdf does not exist
user asdf5: directory /home/asdf5 does not exist
duplicate shadow password entry
delete line 'bin:*:14777:0:99999:7:::'? y
duplicate shadow password entry
delete line 'daemon:*:14777:0:99999:7:::'? y
duplicate shadow password entry
delete line 'sync:*:14777:0:99999:7:::'? y
duplicate shadow password entry
delete line 'shutdown:*:14777:0:99999:7:::'? y
duplicate shadow password entry
delete line 'news:*:14777:0:99999:7:::'? y
duplicate shadow password entry
delete line 'nobody:*:14777:0:99999:7:::'? y
duplicate shadow password entry
delete line 'nscd:!!:14777:0:99999:7:::'? y
duplicate shadow password entry
delete line 'mailnull:!!:14777:0:99999:7:::'? y
duplicate shadow password entry
delete line 'nfsnobody:!!:14777:0:99999:7:::'? y
duplicate shadow password entry
delete line 'haldaemon:!!:14777:0:99999:7:::'? y
duplicate shadow password entry
delete line 'ntp:!!:14777:0:99999:7:::'? y
duplicate shadow password entry
delete line 'distcache:!!:14777:0:99999:7:::'? y
duplicate shadow password entry
delete line 'named:!!:14777:0:99999:7:::'? y
no matching password file entry in /etc/passwd
delete line 'netdump:!!:13459:0:99999:7:::'? y
no matching password file entry in /etc/passwd
delete line 'beagleindex:!!:13459:0:99999:7:::'? y
no matching password file entry in /etc/passwd
delete line 'defang:!!:13468::::::'? y
no matching password file entry in /etc/passwd
delete line 'mailman:!!:14250::::::'? y
pwck: the files have been updated



Whew!

7 thoughts on “Repair /etc/passwd and /etc/group

  1. simalango

    Thank you very much, it’s work very good!

    Nice tutorials!

    Reply
  2. risa

    it really works,after deleting user “uucp” & “operatr”

    Reply
  3. Girish

    Hi,

    I edited my passwd file from “ocnos::1000:0:Z*******s:/home/ocnos:/usr/local/sbin/cmlsh” to ocnos::1000:0:Z*******s:/home/ocnos:/usr/local/sbin/ using vi editor…..I again changed to how it was before
    “ocnos::1000:0:ZebOS_ocnos:/home/ocnos:/usr/local/sbin/cmlsh”

    After this i’m not able to telnet to machine…i’m getting access denied. I later realised that passwd files should be not edited using windows editor. Now the passwd file is corrupted.

    Can u please help on this?

    Reply
    1. Ominous

      Late reply, but maybe it will help someone.
      It put windows carriage returns in, use dos2unix to fix it

      Reply
  4. aaa

    你妹,按你来的做。服务器都连不上了。
    不要害人了

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.