Created
June 8, 2022 15:31
-
-
Save sas-starbuck/41af55584abde12d41521e47975eb15f to your computer and use it in GitHub Desktop.
create local user account (non-admin)
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/sh | |
#https://gist.github.com/dimitardanailov/6acdd54ab67d5a25c0229b2fe5bbb42b | |
#https://apple.stackexchange.com/questions/82472/what-steps-are-needed-to-create-a-new-user-from-the-command-line/84039#84039 | |
LOCAL_USER_FULLNAME="Testing" # The local user's full name | |
LOCAL_USER_SHORTNAME="testing" # The local user's shortname | |
LOCAL_USER_PASSWORD="password!" # The local user's password | |
LOCAL_USER_HINT="terrible pwd!" # The local user's password | |
IMAGEURL= # local user's picture, comment out if not needed, plus lines 24-25 | |
LastID=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -n | tail -1) | |
NextID=$((LastID + 1)) | |
if [ $LOCAL_USER_SHORTNAME = "$(dscl . -list /Users UniqueID | awk '{print $1}' | grep -w $LOCAL_USER_SHORTNAME)" ]; then | |
echo "User already exists!" | |
exit 0 | |
fi | |
. /etc/rc.commond | |
dscl . create /Users/$LOCAL_USER_SHORTNAME | |
dscl . create /Users/$LOCAL_USER_SHORTNAME RealName "$LOCAL_USER_FULLNAME" | |
dscl . create /Users/$LOCAL_USER_SHORTNAME hint "$LOCAL_USER_HINT" | |
curl "$IMAGEURL" --output /tmp/img.png | |
dscl . create /Users/$LOCAL_USER_SHORTNAME picture "/tmp/img.png" | |
dscl . passwd /Users/$LOCAL_USER_SHORTNAME $LOCAL_USER_PASSWORD | |
dscl . create /Users/$LOCAL_USER_SHORTNAME UniqueID $NextID | |
dscl . create /Users/$LOCAL_USER_SHORTNAME PrimaryGroupID 20 | |
dscl . create /Users/$LOCAL_USER_SHORTNAME UserShell /bin/bash | |
dscl . create /Users/$LOCAL_USER_SHORTNAME NFSHomeDirectory /Users/$LOCAL_USER_SHORTNAME | |
createhomedir -u $LOCAL_USER_SHORTNAME -c | |
echo "New user $(dscl . -list /Users UniqueID | awk '{print $1}' | grep -w "$LOCAL_USER_SHORTNAME") has been created with unique ID $(dscl . -list /Users UniqueID | grep -w "$LOCAL_USER_SHORTNAME" | awk '{print $2}')" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment