I don't yet have the reputation to answer, but if you're looking for how to do this from single_user mode (a security reset) then you'll need to reboot holding down Command-S, gain write access to the disk per on-screen details, and then rm /var/db/.AppleSetupDone which will let you create a new admin account. Hope this helps someone
–
New AlexandriaJan 3 '13 at 22:26

I created a script that populates our Open Directory Master with new users, and then calls sudo createhomedir -s (IIRC) on the Open Directory Replicas / Fileshares, and they happily create the home directories.
–
Clinton BlackmoreJun 5 '09 at 23:07

2

dscl -list is limited to 256 results, so if you have more than 256 users, this technique will fail to guarantee a unique UID.
–
smokrisSep 14 '12 at 18:57

I've leveraged the different answers here to come up with what I think is a nice script to create user accounts. Admittedly, this isn't designed for running a command at a time from ssh; it is moreso designed to be a script run when compiling a package-based image of OS X (as created by Casper Imaging or InstaDMG).

The script does let you specify which groups a user should belong to. It appears to me that this might differ depending upon the version of OS X you are running. I get different results when I run id as an admin on OS X 10.6 than I do when running as an admin on OS X 10.5.

In another answer, Elliott warns that the 'createhomedir -c' command, toward the end, will create accounts for all users in the directory you are bound to. (The '-c' option, in the man page, 'creates home directories for local home paths only.') There is another option, '-u username', that may work better.
–
Clinton BlackmoreSep 21 '10 at 18:52

hello i'm using the script above. So it adds my new user but when the user will connect to his calendar it says that he doesn't have the permissions! Can you help me ?
–
jimmyJan 24 '11 at 2:50

@jimmy: I'd recommend asking a new question on serverfault and link to this answer rather than just asking a question in the comments, which will be seldom seen. I would expect the permissions to be right. Using 'chown' and 'chmod' can help if you can identify a file that does not have the correct permissions ... but I don't know which one it would be.
–
Clinton BlackmoreJan 26 '11 at 18:31

dscl -list is limited to 256 results, so if you have more than 256 users, this technique will fail to guarantee a unique UID.
–
smokrisSep 14 '12 at 18:58