Home > Mac administration, Mac OS X > Adding AD domain groups to /etc/sudoers

Adding AD domain groups to /etc/sudoers

A recent discussion on the MacEnterprise list focused around how to give members of Active Directory groups the ability to run commands as root using the sudo command-line utility. This would allow the users in those groups the ability to run some or all commands with root privileges in Terminal without having to give those accounts administrative privileges on the Mac in question.

To do this, you would need to add an entry to the /etc/sudoers file. /etc/sudoers gives listed users or groups the ability to execute commands while having the privileges of the root user.

Editing /etc/sudoers

To edit /etc/sudoers safely, make sure to use the visudo utility. This application will do a sanity check on your changes to /etc/sudoers before putting them into production.

visudo uses vi as its editor. If you haven’t used vi previously, I recommend doing some research on vi commands  before launching visudo.

Adding entries to /etc/sudoers

Adding the following entry to /etc/sudoers would allow you to give full sudo permissions to an AD group named ITadmins:


%DOMAIN\\ITadmins      ALL=(ALL) ALL

Because a number of AD groups have spaces in the names, you’ll need to escape the spaces using backslashes. For example. adding the following entry to /etc/sudoers would allow you to give full sudo permissions to an AD group named Group Name With Spaces:


%DOMAIN\\Group\ Name\ With\ Spaces       ALL=(ALL) ALL

In both cases, replace DOMAIN with your AD domain’s name.

  1. Richard Purves
    December 16, 2012 at 1:24 pm

    Does this just affect accounts on terminal or will it also enable admin status on locally logged in AD accounts too?

    • Richard Purves
      December 16, 2012 at 1:26 pm

      Nope it doesn’t. That’ll teach me to post before RTFM.

  2. Ale
    December 18, 2016 at 3:23 am

    Thanks mate! that was exactly what I was looking for since one hour ago 🙂

  3. January 5, 2017 at 9:11 pm

    do you know how to do this on Casper

  4. hunter3740
    March 22, 2017 at 2:07 pm

    Any clues on how to speed up the sudo command (seems like it queries the entire active directory each time I run the command; makes it so slooooow)? Is there a way to tell winbind to only search one specific group and not entire directory (i.e. because only one specific (admin) group would ever be using ssh or console to my Debian servers)?

    have fqdn in /etc/hosts and %groupname in /etc/sudoers

    I’d be okay with locking people out of this box if it would help speed up that command

  5. Joao Paulo
    March 9, 2018 at 6:02 pm

    THANK YOU SO MUCH!!!
    MUITO OBRIGADO!!!

  6. May 7, 2018 at 1:41 pm

    I was trying group names without domain prefix and was failing for many days.
    No other tutorial suggested me to add domain prefix for AD groups. Your idea worked for me. Thanks a lot!

  7. Rafael Ruales
    January 25, 2019 at 7:28 pm

    This works perfectly thank you

  1. No trackbacks yet.

Leave a comment