Create user, group and edit group membership in macOS

Quick commands to create user and group in macOS with specific uid and gid, and to add a specific user to newly created group.

Add group

sudo dscl . -create /Groups/<name> gid <gid>

Add user

sudo dscl . -create /Users/<name>

sudo dscl . -create /Users/<name> UniqueID "<uid>"

sudo dscl . -create /Users/<name> PrimaryGroupID <gid>

Add existing user to new group

sudo dscl . append /Groups/<name> GroupMembership <user>

Wish macOS actually used useradd/groupadd like linux systems, ah well!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.