Created
July 10, 2012 23:51
-
-
Save jhbush/3087016 to your computer and use it in GitHub Desktop.
Create User Script
This file contains 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 | |
# This script creates a user account under Mac OS X | |
# === Typically, this is all you need to edit === | |
USERNAME= | |
FULLNAME= | |
PASSWORD= | |
# A list of (secondary) groups the user should belong to | |
# This makes the difference between admin and non-admin users. | |
# Leave only one uncommented | |
#SECONDARY_GROUPS="staff" # for a non-admin user | |
SECONDARY_GROUPS="admin _lpadmin _appserveradm _appserverusr" # for an 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)) | |
USERID=501 | |
# 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 . -append /Users/$USERNAME Picture "/Library/User Pictures/Flowers/Lotus.tif" | |
dscl . -passwd /Users/$USERNAME $PASSWORD | |
# Add use to any specified groups | |
for GROUP in $SECONDARY_GROUPS ; do | |
dseditgroup -o edit -t user -a $USERNAME $GROUP | |
done | |
#Create the home directory | |
createhomedir -c -u $USERNAME | |
echo "Created user #$USERID: $USERNAME ($FULLNAME)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does this script work in Catalina?