How to change user ID on leopard

changing uid in earlier versions of Mac OS 10

Introduction

If you are integrating your stand-alone machine into an existing local network, you might find that your local user id is different from your network user ID. In order to access network resources as you, you need a single UID. In this example, you are the user nouchine and your local machine is connected to a netinfo or ldap server called server.



Read the local UID:


dscl . -read /Users/nouchine | grep UniqueID
uid: 501

Read the network UID:


dscl /LDAPv3/ldap.company.com -read /Users/nouchine | grep UniqueID
uid: 2645
dscl localhost -read /NetInfo/root/Users/nouchine UniqueID
uid: 2645

Or if you are on NIS:


ypcat passwd.byname | grep nouchine | cut -d: -f4
2645


In this example, your local UID is 501 and your network UID is 2645. Since these are different, you will not be able to write to your NFS directories. To make your local UID match your network UID, perform the following:

Log in as root (or a user with administrative privilages) from the login window. You ought not be logged in anywhere as the user whose UID you are going to change.

(1) Change the local UID to the network UID


dscl . -change /Users/nouchine UniqueID 501 2645
Confirm:
dscl . -read /Users/nouchine | grep UniqueID

(2) Change the owner of your files from the old UID to the new one. This needs to be done on every file system that you wrote to as the old user. At a minimum, this will be /Users/nouchine and /Library, and you might find others.


find /Users/nouchine -user 501 -exec chown 5464 {} \;
find /Library -user 501 -exec chown 5464 {} \;
find /Applications -user 501 -exec chown 5464 {} \;
find /usr -user 501 -exec chown 5464 {} \;

There are a few files that have the old UID as part of their names:

/.Trashes/501
/Library/Caches/com.apple.IntlDataCache.501
/Library/Caches/com.apple.IntlDataCache.sbdl.501
/Library/Caches/com.apple.user501pictureCache.tiff

change these with:


mv /.Trashes/501 /.Trashes/5464
cd /Library/Caches
mv com.apple.IntlDataCache.501 com.apple.IntlDataCache.5464
mv com.apple.IntlDataCache.sbdl.501 com.apple.IntlDataCache.sbdl.5464
mv com.apple.user501pictureCache.tiff com.apple.user5464pictureCache.tiff

If these weren't changed to the new UID before, change them now:

chown 5464 /Library/Caches/*5464*

The .Trashes/501 directory exists on every volume you've mounted in the past, included those on USB keys. If you don't change them, it will be most likely unnoticable because the old directory will simply ignored and a second directory with the new UID created. However, if there are a large number of files in the trash under the old UID, you'll never get that space back. Deal with this now by either changing the UID and name, or by deleting the directory.

The instructions above handle the UID. You might find that on the remote systems that you belong to certain groups to which you do not belong on the local system. For example, if you are part of the group "autism" on the remote server, but not locally, you won't be able to write to files or directories owned by other members of the group.

In this case, you will need to create the group locally. Here the GID has been determined to be 1135. In most cases, this will be obvious because you will see the GID instead of the group name when you ls -l.


dscl . -create /Groups/autism
dscl . -create /Groups/autism PrimaryGroupdID 1135
dscl . -create /Groups/autism Password \*

Make yourself a member.

dscl . append /Groups/autism GroupMembership nouchine