Create a Unix User / Group from the command line on MacOS X

by Wolfram Saringer  (2011-10-17)
last change: 2013-02-08

% sudo dscl . -create /Users/luser
% sudo dscl . -create /Users/luser UserShell /bin/bash
% sudo dscl . -create /Users/luser RealName "Realname for user"
% sudo dscl . -create /Users/luser UniqueID "1010"
% sudo dscl . -create /Users/luser PrimaryGroupID 80
% sudo dscl . -create /Users/luser NFSHomeDirectory /Users/luser

Create a group:
% sudo dscl . -create /groups/tomcat
% sudo dscl . -append /groups/tomcat gid 230
% sudo dscl . -append /groups/tomcat passwd "*"

Add a user to this group (replace username with the correct value):
% sudo dscl . -append /groups/tomcat GroupMembership luser

in part derived from an answer at Serverstack:

all articles represent the sole opinion of their respective author. all content comes without any warranty for correctnes, despite due diligence.