Changing uid/UniqueID on OS X Yosemite (10.10)

3 minute read Published:

Based on the [url=http://www.inteller.net/notes/change-user-id-on-snow-leopard]notes on inteller.net[/url] I changed the uid of my user stefan on OS X. I wanted to do this because I use NFS for storing all important data and then the same uid is important to have the corect rights on the files.

First I created a new user with admin rights and logged in with that user. Then I became root by using sudo [code] $ sudo -i

[/code]

—8<—

  1. Change UID

Read the uid (given Alice as the user’s name, 501 as old and 1001 as the new uid):

dscl . -read /Users/stefan UniqueID

UniqueID: 501

Change uid:

dscl . -change /Users/stefan UniqueID 501 1001

Verify that the uid has changed:

dscl . -read /Users/stefan UniqueID

UniqueID: 1001

  1. Change ownership of the user’s files

As noted in the article I referred to earlier, the ownership of the user’s files has to be changed on every filesystem the user had written to. So do (at least) the following (updated, thanks pir, Tomás & Creeture):

find /Users/stefan /Library /Applications /usr /private/var/ -user 501 -print0 | xargs -0 chown -h 1001

If you want to be sure that you changed the ownership of all files of the root partition (“Macintosh HD” or whatever you named it), you could do the following (but be prepared that this takes considerably longer, especially if you have much data in /Users):

find -xP / -user 501 -print0 | xargs -0 chown -h 1001

A simple test if there are files left that are owned by the old uid:

find -xP / -user 501 -ls

Remember that you have to check the ownerships on every filesystem that the user had written to. 3. Rename special files and folders

But that was not all. Mac OS X has some special files and folders that have the (old) uid as part of their names. These include (on my Mac, ymmv):

/.Trashes/501
/Library/Caches/com.apple.ImageCaptureExtension2.ICADeviceDatabase.501
/Library/Caches/com.apple.ImageCaptureNotifications.DeviceDiscoveryDatabase.501
/private/var/db/launchd.db/com.apple.launchd.peruser.501
and possibly some files in /private/var/folders/ud/(some ugly dir name)/-Caches-/

For every of the above you have to do something like (you may have a look at Guido’s tip below - thanks Guido! -, but I haven’t tested that and my Bash skills are inferior, apparently ;):

mv /.Trashes/501 /.Trashes/1001

Finder creates folders like these on every (local) filesystem you move things to Trash from. Therefore, you have to check every filesystem for the existence of a folder named .Trashes/501 like, for example, /Volumes/My External Disk/.Trashes/501. If you don’t do this, you may possibly end up in wasted space (but I haven’t checked this).

If you want to check if there are remaining files or directories that have the old uid in their name, you can, again, use find (thanks Tim!):

find -xL / -name “*501”

  1. Finalize: reboot

As Thomas stated below, it’s wise to reboot your machine after this procedure (you’re absolutely right Thomas). Otherwise strange things happen if you try to log in with the changed user id. —8<—

Recent posts
- full list -