willbryant.net

Changing system user account homedirs on Mac OS X

Published Mon 25 February 2008 11:46 (+1300)
Tagged

While I've grown to like the features of both PostgreSQL and Mac OS X, administering them is a lot more arcane than MySQL and Linux.

Today I've been upgrading from PostgreSQL 8.2 to 8.3, which amongst other things meant changing the homedir for the postgresql account that I run the server under.

Under Linux, this is easy – open up /etc/passwd and change it. Under Mac OS X, for ‘hidden’ accounts (ie. anything not shown in the Accounts preferences pane) you need to use the Directory Services system:

$ sudo dscl .

You need the dot there at the end, BTW.

> cd /Users/postgres

(Or /Users/whatever_user_account_you're_interested_in)

/Users/postgres > read
AppleMetaNodeLocation: /Local/Default
GeneratedUID: 81A7F432-9135-4EA1-9097-993BC70AA7A5
NFSHomeDirectory: /opt/local/var/db/postgresql82
Password: *
PrimaryGroupID: 500
RealName:
 PostgreSQL-82\ Server
RecordName: postgres
RecordType: dsRecTypeStandard:Users
UniqueID: 500
UserShell: /bin/sh

This shows you all the account properties. You'll need to know the current value, because:

/Users/postgres > change . NFSHomeDirectory /opt/local/var/db/postgresql82 /opt/local/var/db/postgresql83

- you supply both the old and new values to the change command (nice oplocking scheme, I likey).