# Etc.passwd on OS X

**URL:** <https://www.ruby-forum.com/t/etc-passwd-on-os-x/177190>\
**Category:** Ruby\
**Created:** [October 13, 2009, 2:28am UTC](https://www.ruby-forum.com/t/etc-passwd-on-os-x/177190 "2009-10-13T02:28:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rooster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71c47a/32.png) [@rooster](https://www.ruby-forum.com/u/rooster)\
**Post date:** [October 13, 2009, 2:28am UTC](https://www.ruby-forum.com/t/etc-passwd-on-os-x/177190/1 "2009-10-13T02:28:20Z")

</div>

Hi,

I’m wondering if anyone knows how the Etc class locates users for OS X.

The documentation suggests that it simply parses the /etc/passwd file  
and returns a list of the users in there. However, I don’t think this  
is true for OSX. When I look through my /etc/passwd file I notice that  
there are several users missing, including the username that Iogin with.

However, the Etc class still manages to find all of the users on my  
system… For OSX, does the Etc class inspect an alternate file? If  
so, what file is it getting its information from?

Thanks,  
Steven

---

<div class="post-metadata">

**Author:** ![rooster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71c47a/32.png) [@rooster](https://www.ruby-forum.com/u/rooster)\
**Post date:** [October 13, 2009, 3:25am UTC](https://www.ruby-forum.com/t/etc-passwd-on-os-x/177190/2 "2009-10-13T03:25:54Z")

</div>

Steven,

OS/X doesn’t use the Unix/Linux /etc/passwd and /etc/group files.  
Instead it uses  
netinfo (or another directory service). There’s a command line tool  
dscl that is quite powerful.  
See below (ignore the names) or look at the manpages for dscl

Peter

```
 # Create user mr-potato-head
 sudo "/usr/bin/dscl . -create /Users/mr-potato-head UniqueID 2400"
 sudo "ditto --rsrc '/System/Library/User\ Template/

```

English.lproj/’ /Users/mr-potato-head"  
sudo “chown -R mr-potato-head /Users/mr-potato-head”  
sudo “/usr/bin/dscl . -create /Users/mr-potato-head  
NFSHomeDirectory /Users/mr-potato-head”  
# mr-potato-head user needs admin access  
sudo “/usr/bin/dscl . -append /groups/wheel GroupMembership mr-  
potato-head”  
# Create user mr-radish  
sudo “/usr/bin/dscl . -create /Users/mr-radish UniqueID 2410”  
sudo “ditto --rsrc ‘/System/Library/User\ Template/  
English.lproj/’ /Users/mr-radish”  
sudo “chown -R mr-potato-head /Users/mr-radish”  
sudo “/usr/bin/dscl . -create /Users/mr-radish NFSHomeDirectory /  
Users/mr-radish”  
sudo “/usr/bin/dscl . create /Groups/vegetable PrimaryGroupID 2420”  
sudo “/usr/bin/dscl . append /groups/vegetable GroupMembership mr-  
potato-head”  
sudo “/usr/bin/dscl . append /groups/vegetable GroupMembership mr-  
radish”

---

<div class="post-metadata">

**Author:** ![rooster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71c47a/32.png) [@rooster](https://www.ruby-forum.com/u/rooster)\
**Post date:** [October 13, 2009, 4:03am UTC](https://www.ruby-forum.com/t/etc-passwd-on-os-x/177190/3 "2009-10-13T04:03:57Z")

</div>

On Oct 12, 2009, at 8:28 PM, Steven H. wrote:

> However, the Etc class still manages to find all of the users on my  
> system… For OSX, does the Etc class inspect an alternate file? If  
> so, what file is it getting its information from?

Without looking at the Ruby source I would guess that ruby uses the  
POSIX getpwnam function. The man page (“man getpwnam”) for that  
function  
says:

> These functions obtain information from DirectoryService(8),  
> including records in /etc/passwd which is described in passwd(5).  
> Each entry in the database is defined by the structure passwd found  
> in the include file \<pwd.h\>

So the magic is happening in the Apple supplied getpwnam function  
which accesses Mac OS’s DirectoryService daemon (as well as the  
static /etc/passwd file apparently) for the actual data.

Gary W.

---

<div class="post-metadata">

**Author:** ![rooster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/71c47a/32.png) [@rooster](https://www.ruby-forum.com/u/rooster)\
**Post date:** [October 13, 2009, 5:59am UTC](https://www.ruby-forum.com/t/etc-passwd-on-os-x/177190/4 "2009-10-13T05:59:40Z")

</div>

Thanks Gary and Peter!

Best,  
Steven
