How to add user to a group from Mac OS X command line?
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'.
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.
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)