How to change user ID



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 server called server.



Compare the local and network UID:


niutil -read . /users/nouchine | grep uid
uid: 501
niutil -read -t server/network /users/nouchine | grep uid
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. We will change the local UID to 2645. Since these are different, you will not be able to write to your NFS directories. To change your local UID, perform the following:

Log in as root from the login window. You should not be logged in anywhere as the user whose UID you are going to change.

(1) Change the local UID to the network UID


niutil -createprop . /users/nouchine uid 2645
Confirm:
niutil -read . /users/nouchine | grep uid

(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