Are formats of files /etc/shadow and /etc/passwd same on all unix and unix-like systems same or are there significant differences?
I mean syntax of files, not file location or name
shadowusers
Are formats of files /etc/shadow and /etc/passwd same on all unix and unix-like systems same or are there significant differences?
I mean syntax of files, not file location or name
Best Answer
As far as I know, all unix variants have an
/etc/passwd
file with the traditional layout, for the sake of applications that read the file directly. Each line in the file contains colon-separated records which correspond tostruct passwd
fields:One thing that varies between systems is how much liberty you can take with the syntax. For example, GNU libc (i.e. Linux) ignores lines that begin with
#
: they are comments. GNU libc also ignores whitespace at the beginning of a line, so they can be indented. An invalid line might cause programs to stop processing the file or to skip to the next line.Most modern systems no longer store an encrypted password in the second field. The content of that field is not a reliable indication of whether the user has a password set (and even if you found that out, this is not a reliable indication of whether the user can log in, because there are many other authentication methods such as SSH keys, one-time passwords, biometrics, smartcards, …).
When passwords aren't in
/etc/passwd
, where they are is system-dependent. The Rosetta Stone for Unix mentions many unix variants./etc/shadow
, and this has been copied by others including Linux. Linux and Solaris shadow files have the same format; I don't know if the other systems that have a file called/etc/shadow
use the same format./etc/master.passwd
, and additionally have database files for faster access, updated bypwd_mkdb
.Remember that
/etc/passwd
hasn't been guaranteed to contain the full list of users for a couple of decades: users can come from other databases such as NIS (YP) or LDAP. As a system administrator, avoid edit the/etc/passwd
file directly; usevipw
instead, if your system provides it (and if it doesn't, consult your manuals to see what method is recommended to modify the user database).What I wrote above goes for groups, too. The fields in
/etc/group
arestruct group
members: group name, password (largely unused), numerical group id, and a comma-separated list of user names (the users who have this group as a secondary group). Linux has a/etc/gshadow
file, but this is rarely used, as group authentication is not widely practiced.