I am trying to add a user to a group from the command line but can't figure out how. Specifically this is on Mac OS X Server version 10.5.8.

The user is 'john', the groups are 'admin' and 'wheel'.


4 Answers 4

sudo dseditgroup -o edit -a john -t user admin
sudo dseditgroup -o edit -a john -t user wheel

It's also possible to do this with dscl, but to do it properly you need to both add the user's short name to the group's GroupMembership list, and add the user's GeneratedUID to the group's GroupMembers list. dseditgroup takes care of both in a single operation.

  • 16
    Sorry i'm not too cleared with the usage. Lets say i want to add the username bob into wheel, will it be sudo dseditgroup -o edit -a bob -t user wheel ? Commented Mar 2, 2014 at 3:46
  • 6
    @夏期劇場: Correct. Commented Mar 2, 2014 at 4:41
  • 2
    I had to add -p as well so I could enter my password. Commented Apr 27, 2014 at 18:23
  • 5
    Still valid on osx 10.9.2; copy and paste if you are searching for apache: sudo dseditgroup -o edit -a `whoami` -t user _www
    – vault
    Commented Jul 16, 2014 at 13:30
  • 2
    Working in El Capitan (10.11.6) as well!
    – alexw
    Commented Nov 23, 2016 at 20:16

For those who are looking for the same answer to newer versions of Mac OS, I've found this: To add a user to a group, you need this command ($USER is the current logged-in user) :

$ sudo dscl . append /Groups/wheel GroupMembership $USER

I was trying to add my user to the wheel group, to be able to manipulate the /Library/WebServer/Documents folder. Besides that, I had to change the permissions to that folder, as by default it is 755. I've changed it to 775 with:

$ sudo chmod -R 775 /Library/WebServer/Documents

This way I can manipulate the folder content without changing the owner of the folder.

ps. Still working on Catalina (10.15.3)

  • 1
    Can anyone confirm whether this works on 10.14 (mojave) ?
    – Sary
    Commented Feb 8, 2019 at 8:28
  • 2
    It works for me on 10.14.4.
    – mwfearnley
    Commented May 14, 2019 at 10:44
  • 1
    Great. works with Mojave 10.14.5. Thanks for sharing! Commented Jun 4, 2019 at 19:14
  • 1
    @GordonDavisson's answer seems also to work on recent versions (I just used it on Ventura), and says that, in addition to this step, one should also add the user's UID to the group's GroupMembers list.
    – LSpice
    Commented Mar 31, 2023 at 1:12
  • 1
    works on macos Ventura 13.5 (well, worked once) Commented Nov 12, 2023 at 0:47

Check out this link:


Adding a user is something easily accomplished using the built in GUI tools that ship with OS X, however any power user can appreciate the possible efficiency gained from using the command line. So in the spirit of efficiency here are the steps necessary to add a user to your Mac OS X system all with our good friend, Terminal.app.

The important bit is here:

Create and set the user’s group ID property.

dscl / -create /Users/toddharris PrimaryGroupID 1000
  • tried it with sudo dscl . -append /Groups/admin GroupMembership username and though it added the user to "admin" but it also added a bunch of other groups like com.apple.sharepoint.group.1 and com.apple.access_screensharing ect... ?!?
    – Meltemi
    Commented Nov 23, 2010 at 3:01
  • That is strange. On the other hand, perhaps these are groups that have been associated with that user, or it somehow inherited them from elsewhere.
    – user3463
    Commented Nov 23, 2010 at 3:13
  • Did you read through the man pages for dscl at all?
    – user3463
    Commented Nov 23, 2010 at 3:17

on macOS "Sonoma", I added a user to a group with this script:

#!/bin/bash -ve

sudo grep admin /etc/sudoers


# add $USER to "admin" group
sudo echo $USER
sudo dseditgroup -o edit -a $USER -t user admin
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Jan 2 at 19:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .