/etc/shadow contains the username, but not the uid. Is there a specific reason, why a char * field was chosen over an int?

For direct username->password check this might be quicker, but for relations to /etc/passwd a string-comparison on each user seems a little expensive.

I'd like to know the rationale behind this decision.

1 Answer 1


There could be multiple users with the same uid (but different name, home directory, shell, etc) in /etc/passwd. And that was current practice -- IIRC even today, there's a toor "alternate root" account on BSD.

If the /etc/shadow passwords were indexed by uid instead of user name, then which /etc/passwd entry would each of them correspond to?

  • Is this actually the real reason? As I understand from here: askubuntu.com/a/427115/594043, two user should actually not have the same uID.
    – DarkTrick
    Commented Jan 13, 2020 at 13:50
  • well, they could've matched & duplicate all the fields from /etc/passwd in /etc/shadow (as it's the case in some systems), but they chose not to. Since they decided to match on a single key, using the uid would've broken setups which used multiple usernames with the same uid (which really exist, no matter if it's good idea or not).
    – user313992
    Commented Jan 13, 2020 at 15:21
  • 1
    It's generally not a great idea to have multiple usernames for the same uid, but if your system depends on root having /bin/csh as its shell, and your system administrators loathe csh, it might be helpful. Some BSD systems provide a toor username with uid 0 and shell /bin/sh. Commented Jan 13, 2020 at 18:46
  • @Mark BSD systems also don't use /etc/shadow, but an /etc/master.passwd which duplicates all the fields from /etc/passwd (name, uid, homedir, etc). Anyways, multiple users with the same uid could not work if /etc/passwd and /etc/shadow had the uid as the "common key". But they would work if both the user name and the uid were matched.
    – user313992
    Commented Jan 14, 2020 at 18:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .