48

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?

6 Answers 6

33

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.

5
  • I went looking for something like that (Directory Utility) - and it isn't there in my Snow Leopard install...any idea what I could be missing - how it got there on yours? Sep 21, 2010 at 17:09
  • Hmmm...Apple says "Mac OS X v10.5 includes two utilities used to bind computers to Microsoft Active Directory. Directory Utility is an application, and dsconfigad is a command-line utility accessed through Terminal. Both may be used to configure the Active Directory connector in Directory Utility." Sep 21, 2010 at 17:23
  • It's not installed in the advertised location, nor does it appear in spotlight. Looks like my password file is lying to me.
    – Steve Weet
    Sep 21, 2010 at 17:28
  • My password file tells the same fib. I did find dsconfigad. Sep 21, 2010 at 22:41
  • 2
    Added the new location of directory utility. Aug 22, 2013 at 19:40
11

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.

4

OS X doesn't use the UNIX/LINUX /etc/passwd files. Instead, it stores it in NetInfo. The command used to interact with NetInfo is the directory service command utility, or dscl.

I'm not familiar with the commands, but I'm sure a simple man dscl wouldn't hurt anyone.

2
  • 3
    NetInfo was replaced by Directory Services as of Mac OS X 10.5 and newer.
    – Chealion
    Oct 1, 2010 at 2:27
  • 1
    Which was replace by opendirectoryd.
    – goetz
    Dec 1, 2022 at 23:52
4

I realise this is not directly answering the question but I feel many who run into this question will just want to know how to do a simple query to find user information from the command line. For others along this path just needing to see similar config to the standard unix commands I found this simple command to be useful.

dscl . -read /Users/<putusernamehere> UniqueID PrimaryGroupID NFSHomeDirectory UserShell

You can also do:

dscl . -read /Users/<putusernamehere>

To see everything but be warned it will dump an hex version of the users photo to the screen. If you need other components though its useful to see what is there if you can avoid the JPEGPhoto item.

3

Mac OS X uses Open Directory.

1

This will list all users included in /etc/passwd but also the default user missing from this.

dscl . list /Users

You must log in to answer this question.

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