Skip to content

Instantly share code, notes, and snippets.

@cuibonobo
Created August 11, 2015 14:19
Show Gist options
  • Select an option

  • Save cuibonobo/78053e9e301347a1bbf3 to your computer and use it in GitHub Desktop.

Select an option

Save cuibonobo/78053e9e301347a1bbf3 to your computer and use it in GitHub Desktop.
Create a user from the command line on Mac OS X
#!/bin/bash
# This must be run as root. Needs to ask for password interactively and get the next unique
# user ID automatically, but you get the idea.
USERNAME='username'
USER_ID=510
DISPLAY_NAME='User Name'
PASSWORD='password'
dscl . -create /Users/${USERNAME}
dscl . -create /Users/${USERNAME} UserShell /bin/bash
dscl . -create /Users/${USERNAME} RealName "${DISPLAY_NAME}"
dscl . -create /Users/${USERNAME} UniqueID ${USER_ID}
dscl . -create /Users/${USERNAME} PrimaryGroupID 1000
dscl . -create /Users/${USERNAME} NFSHomeDirectory /Local/Users/${USERNAME}
dscl . -passwd /Users/${USERNAME} ${PASSWORD}
# If you need to make this user an administrator, do:
dscl . -append /Groups/admin GroupMembership ${USERNAME}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment