Name

dscl — stdin  stdout  - file  -- opt  --help --version

Synopsis

dscl [arguments]

We encountered the dscl command in Users and Their Environment when creating and deleting users. It can also create and delete groups. As with users, you must run multiple commands to make a group. Suppose we want a new group named gang. First do the initial creation:

sudo dscl localhost -create /Local/Default/Groups/gang

Give the group the password *, meaning a non-functional password, and a unique positive integer ID:

sudo dscl localhost -create /Local/Default/Groups/gang \
  passwd '*'sudo dscl localhost -create /Local/Default/Groups/gang \
  gid 301

Now add the local user zippy to the group, and check the result with the groups command:

sudo dscl localhost -create /Local/Default/Groups/gang \
  GroupMembership zippy

Now confirm that zippy is a member of the group:

groups zippy
... gang ...

To delete the group, run:

sudo dscl localhost -delete /Local/Default/Groups/gang

You can also list all groups:

dscl . list /groups

Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.