Skip to content

Instantly share code, notes, and snippets.

@technocake
Created November 24, 2012 21:09
Show Gist options
  • Save technocake/4141407 to your computer and use it in GitHub Desktop.
Save technocake/4141407 to your computer and use it in GitHub Desktop.
A script to add a user from cli on mac osx.
#!/bin/sh
#
# Adds a user to a mac.
#
# based on this article: http://osxdaily.com/2007/10/29/how-to-add-a-user-from-the-os-x-command-line-works-with-leopard/
#
# Usage: ./mac_adduser.sh <username> <uid> <gid>
#
username=$1
fullname=$2
uid=$2
gid=$3
# Create a new entry in the local (/) domain under the category /users.
dscl . -create /Users/$username
# Create and set the shell property to bash.
dscl . -create /Users/$username UserShell /bin/bash
# Create and set the user’s full name.
dscl . -create /Users/$username RealName $fullname
# Create and set the user’s ID.
dscl . -create /Users/$username UniqueID $uid
# Create group and set guid
dscl . -create /Groups/$username
dscl . -create /Groups/$username gid $gid
# Create and set the user’s group ID property.
dscl . -create /Users/$username PrimaryGroupID $gid
# Create and set the user home directory.
dscl . -create /Users/$username NFSHomeDirectory /Users/$username
# Set the password.
# dscl . -passwd /Users/$username PASSWORD
# or
passwd $username
# If you would like Dr. Harris to be able to perform administrative functions:
# dscl . -append /Groups/admin GroupMembership $username
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment