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!