How can I create a user with a specific UID?

This question has been asked here before but the answer given was to the question "How do I create a user" and not "How do I create a user with a specific UID". I have to match my users' UIDs with their UIDs on our Linux servers to allow them access to their home folders on a network share. Currently, the only way I can find to do this is to:


  1. Create the user through the usual procedure in Settings -> Users & Groups. UID is chosen as the highest UID + 1
  2. Go to Settings -> Users & Groups -> Right-click on the user -> Advanced Options -> Change the User ID to match the UID on our Linux systems. Let's say in this example that the user's current UID on the Mac is 502 and the UID it needs to be changed to is 2400.
  3. Open a terminal and recursively change ownership on every file owned by UID 502 under / with `sudo find / -uid 502 -exec chown 2400 {} \;`.


I used `dscl` to create users this but dscl was deprecated in favor of sysadminctl, which is broken for my use and likely most enterprise settings. I'd love to just be able to create the user with a one liner with the UID I specify so I don't have to recursively change permissions on /. It's a really messy solution and, depending on the size of the file system and IO, creating a user can take over an hour. The newer `sysadminctl -addUser` is supposed to let you specify a UID but I've never found a syntax that actually works. the -UID parameter is always ignored. Is there a proper syntax for this? I've tried:


sysadminctl interactive -addUser test1 -fullName “Testy Testerton" —UID 2400 -password test1234 -admin

sysadminctl interactive -addUser test1 -fullName Testy Testerton —UID 2400 -password test1234 -admin

sysadminctl interactive -addUser test1 -fullName Testy Testerton —UID=2400 -password test1234 -admin

sysadminctl interactive -addUser test1 -fullName "Testy Testerton" —UID=2400 -password test1234 -admin

sysadminctl interactive -addUser test1 -fullName "Testy Testerton" —UID="2400" -password test1234 -admin


The results are always the same. -UID is just ignored.

admin@Sams-MacBook-Air ~ % sysadminctl interactive -addUser test1 -fullName "Testy Testerton" —UID="2400" -password test1234 -admin

2023-12-01 12:03:16.599 sysadminctl[1591:64410] Creating user record…

2023-12-01 12:03:19.260 sysadminctl[1591:64410] Assigning UID: 502 GID: 20

2023-12-01 12:03:24.722 sysadminctl[1591:64410] Creating home directory at /Users/test1

Posted on Dec 1, 2023 9:15 AM

Reply

Similar questions

3 replies

May 25, 2024 11:13 AM in response to mmulq

Here's how I managed to create a user with a specific UID (on Sonoma):


  • Create the account in System Preferences / Users & Groups
  • Control click on the account to bring up the advanced options, set the UID.
  • At this point the new account is borked due to the home directory, etc being owned by the old UID.
  • The obvious, fix, using chown, fails, presumable due to System Integrity Protection (SIP) ?
  • Delete the account.
  • Recreate the account. For some reason newly recreated account will use the deleted account's UID.


I wish I knew more about exactly why this works and if it will continue to work on future versions of MacOS. Maybe someone more knowledgeable can chime in.

May 25, 2024 12:00 PM in response to lawrence_atherton

lawrence_atherton wrote:

• Here's how I managed to create a user with a specific UID (on Sonoma):

Create the account in System Preferences / Users & Groups
• Control click on the account to bring up the advanced options, set the UID.
• At this point the new account is borked due to the home directory, etc being owned by the old UID.
• The obvious, fix, using chown, fails

Worked fine here.

Dec 1, 2023 10:14 AM in response to mmulq

Correcting —UID to -UID did not help.


sysadminctl interactive -addUser test1 -fullName “Testy Testerton" -UID 2400 -password test1234 -admin

sysadminctl interactive -addUser test1 -fullName Testy Testerton -UID 2400 -password test1234 -admin

sysadminctl interactive -addUser test1 -fullName Testy Testerton -UID=2400 -password test1234 -admin

sysadminctl interactive -addUser test1 -fullName "Testy Testerton" -UID=2400 -password test1234 -admin

sysadminctl interactive -addUser test1 -fullName "Testy Testerton" -UID="2400" -password test1234 -admin


The results are always the same. -UID is just ignored.

admin@Admins-MacBook-Air ~ % sysadminctl interactive -addUser test1 -fullName "Testy Testerton" -UID="2400" -password test1234 -admin

2023-12-01 12:03:16.599 sysadminctl[1591:64410] Creating user record…

2023-12-01 12:03:19.260 sysadminctl[1591:64410] Assigning UID: 502 GID: 20

2023-12-01 12:03:24.722 sysadminctl[1591:64410] Creating home directory at /Users/test1

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How can I create a user with a specific UID?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.