Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two groups on my machine, groupa and groupb - in groupa I have two users, user1a and user2a.

I would like to grant to members of groupa the privs to access groupb resources (run commands, view files etc). I think this probably involves using visudo, but I may be wrong.

What I would like to achieve is the equivalent of:

usermod -a -G groupb user1a
usermod -a -G groupb user2a

but to do it at the group level so that if in future user3a is added to groupa, the user also automatically has the privs for groupb.

As you may have guessed, Unix admin isn't my main area of operation !

How do I go about it?

Thanks in advance


share|improve this question

You can't do nested groups out of the box, like you could do in Active Directory. A previous question got an answer pointing to Linux trustees.

share|improve this answer

I think it can't be done, other than by defining your own wrapper for useradd and enforcing it's use or maybe by a cron script that periodically checks members of groupa and, if necessary adds them to groupb.

share|improve this answer

Using sudo to achieve this requires that the user prefix all their commands with sudo -g groupb. The user won't BE in the groupb group, the user will just have permission to switch to that group and run commands. visudo is the command to edit the sudoers file that controls who is permitted to use sudo for what.

Doing this requires at least 1.7.0 and opens a security exploit in versions up to 1.7.4p3

%groupa ALL = (:groupb) ALL

It is probably better to just manually add the user to both groups. A PAM wizard might be able to automate that process, but it would only work for login shells or applications that use PAM for identifying the user rather than reading /etc/group and /etc/passwd directly

share|improve this answer

Your Answer


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.