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:
- Create the user through the usual procedure in Settings -> Users & Groups. UID is chosen as the highest UID + 1
- 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.
- 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