Changing UID/GID on Mac OS X 10.5

Okay, this is not an astronomy topic, but I got stumped on this for a long time and searching the web, while helpful, didn’t make it exactly obvious. Why would you even want to change GID or UID? Well, I needed to synchronize UID and GID with my NFS server for file sharing. We have two Macs and the accounts had been set up at different times so the UIDs were not the same. I’d already modified everything on the server to match my wife’s iMac G5, and changed things on my Linux laptop to match both of those, so now I had to make the MacBook match the other machines.

The first thing is that changing the nominal user and group ID is simple. But do not try to do this on the account you are logged in as. Create a new, temporary administrator account. Once that’s done, you can proceed with impunity (well, not really…).

Use the System Preference -> System -> Accounts to change the user account. Right-click on the user to bring up the "Advanced Options" menu. You now change the user and group ID.

Once that is done, you will need to open a Terminal window and run chown to change the ownership of the files. Assuming all of the user’s files are in /Users/roland (like mine were), and that the new UID and GID are both 502 (whatever you set in the "Advanced Options" window),

cd /Users
chown -R 502:502 roland

I did the same thing for my wife’s account, but with UID:GID = 501:501 effectively swapping the for our old accounts.

The last remaining problem was to modify the group mappings. When I did a directory listing in /Users, I found the group names hadn’t switched. I suspected they wouldn’t which is why I was looking:

ptolemy-wl:Users tempadmin$ ls -l
total 0
drwxrwx--- 5 root admin 170 Dec 22 2007 Deleted Users
drwxrwxrwt 12 root wheel 408 Dec 29 2007 Shared
drwxr-xr-x+ 16 jonathan jonathan 544 Dec 30 2007 jonathan
drwxr-xr-x+ 17 maria roland 578 Aug 16 09:22 maria
drwxr-xr-x+ 20 matthew matthew 680 Aug 9 14:58 matthew
drwxr-xr-x+ 30 roland maria 1020 Aug 17 19:33 roland
drwxr-xr-x+ 16 tempadmin staff 544 Aug 17 20:10 tempadmin

The last remaining trick is with the new "Directory Services Command Line" tool, aka dscl. You’ll need to do something like this:

ptolemy-wl:Users tempadmin$ sudo dscl
Password:
Entering interactive mode... (type "help" for commands)
> change /Local/Default/Groups/roland PrimaryGroupID 501 502
> read /Local/Default/Groups/roland
AppleMetaNodeLocation: /Local/Default
GeneratedUID: A080E0BB-163E-4DC3-AA15-8A784AECC916
Password: *
PrimaryGroupID: 502
RecordName: roland
RecordType: dsRecTypeStandard:Groups
> change /Local/Default/Groups/maria PrimaryGroupID 502 501
> quit
Goodbye
ptolemy-wl:Users tempadmin$ ls -l
total 0
drwxrwx--- 5 root admin 170 Dec 22 2007 Deleted Users
drwxrwxrwt 12 root wheel 408 Dec 29 2007 Shared
drwxr-xr-x+ 16 jonathan jonathan 544 Dec 30 2007 jonathan
drwxr-xr-x+ 17 maria maria 578 Aug 16 09:22 maria
drwxr-xr-x+ 20 matthew matthew 680 Aug 9 14:58 matthew
drwxr-xr-x+ 30 roland roland 1020 Aug 17 19:33 roland
drwxr-xr-x+ 16 tempadmin staff 544 Aug 17 20:10 tempadmin

And as you can see, now the group names are mapped correctly, too.