# Add a new user with a specific uid and gid

We have a mixed mac and linux environment at work, to make life easy we use the same uid, gid for each user both on the mac and linux side (I believe this is a standard practice).

The problem is, when you add a new user on a mac, there is no way to set the uid and gid "while" you are creating it, so you need to add the user then set the uid/gid and then go and execute a few find ... -exec ...{} ... commands to change the owner and permissions on the home directory for the user that you already made,

Is there a better solution for this?

-

One solution would be to write a simple script to do the whole job at once.

dscl . -create /Users/ali UniqueID 549 PrimaryGroupID 320 RealName "Ali Moeeny"


Or something like that.

-
Problem is, I often find this non unix tools that Apple adds to macosx (like dscl instead of adduser ...) very unintuitive. –  Ali Dec 20 '11 at 20:50
The problem with this is, the new user does not show up in the Users & Groups preference pane afterwards, and you can't actually log in as the user. Or perhaps one should take the “or something like that” addendum a bit more seriously, and actually read the dscl man page … –  Harald Hanche-Olsen Jun 11 '12 at 11:29
If you set the uid above 500 it would show up in the Preferences and you can login as well, I think you can login even if it's uid is below 500 but you need to choose other (pre-lion) and enter both user name and password. –  Ali Jun 12 '12 at 13:34
Didn't work for me, with uid=13799. Anyhow, it was easy enough to change the uid after the fact. (By command line or GUI. I only had to do it for two users …) –  Harald Hanche-Olsen Jun 12 '12 at 17:43
Could you elaborate on how to change the UID for an existing user after the fact? What commands do you need to run or what files do you need to edit to change the user's UID? I'm comfortable with a Unix command line, but want to know the Mac-specific stuff. (On a Unix box, I know I'd need to change /etc/password, /etc/group, and do a chgrp -R to change the uid/gids on all existing user files. What about on MacOSX?) –  D.W. Jul 17 '12 at 6:27