Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 10.5.8

like to add user to 'admin' and 'wheel' groups

share|improve this question
1  
I come back here again and again, thanks! –  Jon z Jun 5 '13 at 19:26

2 Answers 2

up vote 127 down vote accepted
sudo dseditgroup -o edit -a usernametoadd -t user admin
sudo dseditgroup -o edit -a usernametoadd -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.

share|improve this answer
6  
This command seems ridiculously long for such a common operation. –  Code Commander Aug 12 '13 at 23:58
1  
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 ? –  夏期劇場 Mar 2 at 3:46
3  
@夏期劇場: Correct. –  Gordon Davisson Mar 2 at 4:41
    
I had to add -p as well so I could enter my password. –  Vinicius Pinto Apr 27 at 18:23
    
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 Jul 16 at 13:30

Check out this link:

http://osxdaily.com/2007/10/29/how-to-add-a-user-from-the-os-x-command-line-works-with-leopard/

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
share|improve this answer
    
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 Nov 23 '10 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 Nov 23 '10 at 3:13
    
Did you read through the man pages for dscl at all? –  user3463 Nov 23 '10 at 3:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.