Accidentally created user with duplicate UID. How to fix?
2
votes
2
answers
2390
views
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?
Asked by Justin
(123 rep)
Apr 26, 2015, 01:20 AM
Last activity: Apr 26, 2015, 07:05 AM
Last activity: Apr 26, 2015, 07:05 AM