Users don't appear in /etc/passwd on Mac OS X

By examining the /etc/passwd file, I should get a list of all users in the system. However, when dumping the passwd file on Mac OS X I don't see my current username but many entries like these:

  _xgridagent:*:86:86:Xgrid Agent:/var/xgrid/agent:/usr/bin/false
  _appowner:*:87:87:Application Owner:/var/empty:/usr/bin/false
  _windowserver:*:88:88:WindowServer:/var/empty:/usr/bin/false
  _spotlight:*:89:89:Spotlight:/var/empty:/usr/bin/false
  _tokend:*:91:91:Token Daemon:/var/empty:/usr/bin/false

How come I can log into the shell with my username and see that username when I do who?


Solution 1:

The /etc/passwd file is only consulted when the OS is in single-user mode. The "standard" location for account information on OS X is the DirectoryService.

Try man DirectoryService for more information.

The following comment block appears at the top of my password file:

##
# User Database
# 
# Note that this file is consulted directly only when the system is running
# in single-user mode.  At other times this information is provided by
# Open Directory.
#
# This file will not be consulted for authentication unless the BSD local node
# is enabled via /Applications/Utilities/Directory Utility.app
# 
# See the DirectoryService(8) man page for additional information about
# Open Directory.
##

In recent versions of OS X Directory Utility has been moved to /System/Library/CoreServices/Directory Utility.

Solution 2:

There is a set of Directory Services which keeps the information. There are a series of command line tools (dscl for one) to manipulate them (hard) or you can use System Preferences to handle some of them.