Add a user to the admin group via command line

A colleague asked how he could promote a user to an admin via the command line. Here’s how I do it:

niutil -appendprop . /groups/admin users gneagle

replacing gneagle with the user’s shortname. You can add both local and network users to the local admin group.

You should probably do a

niutil -readprop . /groups/admin users

to make sure the user isn’t already in the admin group.

Removing a user from the group:

niutil -destroyval . /groups/admin users gneagle

The tool we’re using is niutil, which presumably stands for NetInfo Utility. man niutil for more information.

Note: niutil is on its way out, and is scehduled to disappear in Leopard (OS X 10.5). So we’ll have to do something using dscl eventually.

Explore posts in the same categories: OS X

5 Comments on “Add a user to the admin group via command line”

  1. systemsboy Says:

    Hey,

    To do this with dscl would look something like the following:

    sudo dscl -p / -append /Groups/admin users gneagle

    The dscl command is nice because it will also work for editing LDAP/OD information. The man page is a bit messy, though, and I’ve found it necessary to modify some of the syntax listed there in order to get things working properly, so be warned. Still, I’ve kept notes on this, and have been using dscl for most directory operations for a while now. Happy to share my findings if you’re ever interested. Just drop me a line.

    -systemsboy

  2. GregN Says:

    Thanks. I’ll post the dscl equivalents in a future post.

  3. DennisU Says:

    Great command for automating tasks.

  4. anna Says:

    This has a good explanation of how dscl replaces niutil with very clear examples http://osxdaily.com/2007/10/29/how-to-add-a-user-from-the-os-x-command-line-works-with-leopard/


  5. [...] Add a user to the admin group via command line [...]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 183 other followers

%d bloggers like this: