
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!
Thank you very much, it’s work very good!
Nice tutorials!
it really works,after deleting user “uucp” & “operatr”
Great article – thanks for your time.
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?
Late reply, but maybe it will help someone.
It put windows carriage returns in, use dos2unix to fix it
Works Great !!! Thank you !!
你妹,按你来的做。服务器都连不上了。
不要害人了