Skip to content

Instantly share code, notes, and snippets.

@toranb
Created July 10, 2015 14:44
Show Gist options
  • Select an option

  • Save toranb/7ffc28143b4e700c0aee to your computer and use it in GitHub Desktop.

Select an option

Save toranb/7ffc28143b4e700c0aee to your computer and use it in GitHub Desktop.
a simple bash script to create a new (non admin) user on OSX Yosemite
#!/bin/bash
USERNAME="toranb"
FULLNAME="Toran Billups"
PASSWORD="put something fun here ????"
SECONDARY_GROUPS="" #non-admin user
if [[ $UID -ne 0 ]]; then echo "Please run $0 as root." && exit 1; fi
# Find out the next available user ID
MAXID=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ug | tail -1)
USERID=$((MAXID+1))
# Create the user account
dscl . -create /Users/$USERNAME
dscl . -create /Users/$USERNAME UserShell /bin/bash
dscl . -create /Users/$USERNAME RealName "$FULLNAME"
dscl . -create /Users/$USERNAME UniqueID "$USERID"
dscl . -create /Users/$USERNAME PrimaryGroupID 20
dscl . -create /Users/$USERNAME NFSHomeDirectory /Users/$USERNAME
dscl . -passwd /Users/$USERNAME $PASSWORD
for GROUP in $SECONDARY_GROUPS ; do
dseditgroup -o edit -t user -a $USERNAME $GROUP
done
createhomedir -c > /dev/null
echo "Created user #$USERID: $USERNAME ($FULLNAME)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment