Add New User on Mac OS X Mountain Lion via CLI

Adding a new Mac OS X user via CLI.

List all existing users IDs in numerical order to see which ones are already taken:

# dscl . -list /Users UniqueID | sort -nk 2

Or simply check that user’s ID we want to use does not exist on a system:

# id 1005
 id: 1005: no such user

Do the same for groups, list all existing group IDs in numerical order:

# dscl . -list /Groups PrimaryGroupID | sort -nk 2

Create a new user for Sandy:

# dscl . -create /Users/sandy
# dscl . -create /Users/sandy UserShell /bin/bash
# dscl . -create /Users/sandy RealName "sandy"
# dscl . -create /Users/sandy UniqueID "1005"
# dscl . -create /Users/sandy PrimaryGroupID 1005
# dscl . -passwd /Users/sandy

Check newly created user’s details:

# dscl . -read /Users/sandy | tail -n 6
 PrimaryGroupID: 1005
 RealName: sandy
 RecordName: sandy
 RecordType: dsRecTypeStandard:Users
 UniqueID: 1005
 UserShell: /bin/bash

Create a home directory:

# mkdir /Users/sandy

Change the ownership appropriately as well as permissions:

# chown sandy:staff /Users/sandy
# chmod 0755 /Users/sandy

Leave a Reply

Your email address will not be published. Required fields are marked *