Accidentally created user with duplicate UID. How to fix? I accidentally created a user with a duplicate UID.  I need advice on how to fix this predicament.

As you can see, running dscl shows two users with the same uid:

dscl . -list /Users uid | sort -nrk 2
jenkins                 9999
original-user           9999


This happened because I was tweaking a package installer script and incorrectly assigned an existing UniqueId when creating a new user.  The UniqueId matches the uid for my own account.  Now when I login to OSX (with my own account), OSX has lost all of my profile settings (ie. Finder shows home for the new user instead of my own, browser has lost my history, etc).

Although OSX shows the profile for the new user, Terminal correctly recognizes the user that I logged in as.  And therefore I'm able to confirm my old files (ie. Document, Downloads) still exist intact.

This is what I ran to get myself in this situation:

uid=9999
gid=$uid
while dscl -search /Groups gid $gid | grep -q $gid; do
    echo "gid $gid is not free, trying next"
    gid=$(($gid + 1))
done
echo "Using gid $gid for jenkins"

dscl . -create /Groups/jenkins PrimaryGroupID $gid

dscl . -create /Users/jenkins UserShell /bin/bash
dscl . -create /Users/jenkins Password '*'
dscl . -create /Users/jenkins UniqueID $uid
dscl . -create /Users/jenkins PrimaryGroupID $gid
dscl . -create /Users/jenkins NFSHomeDirectory "$JENKINS_HOMEDIR"

dscl . -append /Groups/jenkins GroupMembership jenkins


How can I recover?
On Mac OS X, you can change a UID of a local user using System Preferences > Users &amp; Groups.

Open the padlock there to allow changes to be made and then right-click on the user you like to change.

NOTE: You should not be logged in to that account at the time you do the change.

Also, POSIX permissions will follow the UID, so after changing it you may need to change the user ownership for that home folder or you would face not to be able to log in to the changed account.

Command for changing ownership would be:

sudo chown -R &lt;account_name&gt; /path/to/userhomefolder