Read from APUE, just feel curious:
The password file is used every time a user logs in to a UNIX system and every time someone executes an
ls -l
command.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityThe file-system directly associates the numerical UID (User ID) and GID (Group ID) values with the file, not the user name and group name (which are strings). So the ls -l
command (and any other command that displays the user and group owner of a file) need to get the user and group names from somewhere. The /etc/passwd
file is one such source (probably the original and most common source). The manual bears this out - from PASSWD (5) (i.e. the man page for the /etc/passwd
file):
many utilities, like ls(1) use it to map user IDs to usernames
-n
for ls
. This prevents translation of UIDs and GIDs to usernames and group names. I have tested ls -n
with GNU core utils' ls
and the option prevented accessing both /etc/passwd
and /etc/group
as expected.
Mar 8, 2019 at 8:54
strace ls -l
later on, I see aopenat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 4
statement./etc/passwd
on the BSDs. An activenscd
will change things; as will the NSS. So note that this question is based upon a 7th Edition worldview.