#examples from http://ajmccluskey.com/2015/01/managing-users-and-groups-from-the-os-x-terminal/
# List the subdirectories under /Users - i.e. list the users on the system
$ dscl . -list /Users
greententacle
purpletentacle
bernard
...
# List the subdirectories under /Groups - i.e. the groups on the system
$ dscl . -list /Groups
tentacles
daemon
staff
...
# Read all keys in directory and output their values
$ dscl . -read /Users/purpletentacle
PrimaryGroupID: 42
RealName:
Purple Tentacle
UniqueID: 505
UserShell: /bin/bash
# Read a specific key
$ dscl . -read /Users/purpletentacle UniqueID
UniqueID: 505
# List paths with the value of a key
$ dscl . -list /Users UniqueID
greententacle 501
purpletentacle 505
bernard 502
...
We can use dscl to modify this information, or in our case, add new information.
We’re about to create a new user and group, but before we do I should mention
that while you can add a new group with dscl, it’s better to use dseditgroup as
explained on Super User.
# Add the humans group. See man page for explanation of options.
$ sudo dseditgroup -o create -r "Group for Humans not tentacles" humans
# Get the current highest user ID so we can pick something higher
$ dscl . -list /Users UniqueID | awk '{print $3}' | sort -n | tail -1
# Create the user
$ sudo dscl . -create /Users/hoagie
$ sudo dscl . -create /Users/hoagie UniqueID
$ sudo dscl . -create /Users/hoagie UserShell /bin/bash # /usr/bin/false if you do
$ sudo dscl . -create /Users/hoagie RealName "Hoagie"
# Add user to group
$ sudo dseditgroup -o edit -a hoagie -t user humans
our_command_here