Sunday, November 16, 2008

Listing Open Directory Users on OS X Leopard Server

If you want get a list of your users on Open Directory in Leopard Server, you need to use the dscl command from the Terminal. SSH to your server, and do a sudo bash or su - to get into root mode. Then you can run dscl directly with arguments, or, enter its interactive shell mode.

Listing Users with DSCL

Here is how to list users from the command line in Leopard Server:

myhost:~ root# dscl localhost list /Local/Default/Users

myhost:~ root# dscl localhost list /LDAPv3/127.0.0.1/Users

Or, go into interactive mode:

myhost:~ root# dscl

>list Local/Default/Users

>list /LDAPv3/127.0.0.1/Users

You should also be able to email the list to yourself, or, send it to a file:

myhost:~ root# dscl localhost list /LDAPv3/127.0.0.1/Users |sendmail rick.cogley@gmail.com

myhost:~ root# dscl localhost list /LDAPv3/127.0.0.1/Users > /path/to/userlist.txt

An Easier Way with DSCACHEUTIL

There happens also to be a wrapper for this information, that makes things easy. You can use dscacheutil to get a list of users or groups and some relevant information. For example, use dscacheutil with the -q (query) switch and either user or group, like so:

dscacheutil -q user
dscacheutil -q group

The output looks like this:

bash-3.2# dscacheutil -q user
name: _amavisd
password: *
uid: 83
gid: 83
dir: /var/virusmails
shell: /usr/bin/false
gecos: AMaViS Daemon

name: _appowner
password: *
uid: 87
gid: 87
dir: /var/empty
shell: /usr/bin/false
gecos: Application Owner

Hope this helps someone. Enjoy!

No comments: