0

Recently I fixed a problem caused by duplicate entries in /etc/passwd on Linux. To catch it sooner next time I plan to do some basic sanity checks on the file each day, one of which will be that no duplicate uids are found.

But surely this is something many others have done and there is already a well-known tool to lint the passwd and group files for errors? I appreciate it is only a couple of lines of perl, but before reinventing the wheel I feel I should check. Does such a program exist?

Ed Avis
  • 101
  • vipw and vigr may be what you want. – user9517 Aug 08 '14 at 16:58
  • Iain, how do you mean? I don't see in the vipw documentation any discussion of how it sanity-checks the file. – Ed Avis Aug 08 '14 at 17:14
  • They sanity check the files in exit [tag:suck-it-and-see] – user9517 Aug 08 '14 at 18:46
  • @Iain: I've no problems adding and saving a completely bogus `/etc/passwd` entry with `vipw` on Ubuntu and CentOS. – Sven Aug 08 '14 at 20:35
  • Nope, vipw does no such sanity check, at least not on Fedora 20. (I thought you might be referring to the way they lock the files to avoid concurrent edits - which would sometimes avoid duplicate entries being added, though not in this case.) – Ed Avis Aug 09 '14 at 06:26

1 Answers1

2

Have a look into pwck and grpck.

It's in shadow-utils on RedHat based systems and passwd on Debian/Ubuntu.

Sven
  • 97,248
  • 13
  • 177
  • 225
  • pwck does some useful checks, but not this one. You can have two users with the same uid and it does not complain. But I guess pwck is the logical place to add further checks. – Ed Avis Aug 09 '14 at 06:30