Created
July 10, 2015 14:44
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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