The Computer Oracle

How to add user to a group from Mac OS X command line?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 2 Looping

--

Chapters
00:00 How To Add User To A Group From Mac Os X Command Line?
00:22 Answer 1 Score 5
00:55 Accepted Answer Score 328
01:17 Answer 3 Score 20
02:02 Answer 4 Score 0
02:14 Thank you

--

Full question
https://superuser.com/questions/214004/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#macos #mac #commandline #osxleopard

#avk47



ACCEPTED ANSWER

Score 328


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.




ANSWER 2

Score 20


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)




ANSWER 3

Score 5


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



ANSWER 4

Score 0


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

#!/bin/bash -ve

sudo grep admin /etc/sudoers

USER=foo

# add $USER to "admin" group
sudo echo $USER
sudo dseditgroup -o edit -a $USER -t user admin