Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 know I have existing groups and users but I'm not sure about their association. Is there an shell command I can use to list all users or all groups and a command to list all groups/users for a specified user/group?

So something like showusers would list all users, and showgroups -u thisuser would show all the groups that have thisuser in it.

share|improve this question
there is no such command. You need to script it by your self. – Chris Feb 2 '12 at 13:25
up vote 9 down vote accepted

All users:

$ getent passwd

All groups:

$ getent group

All groups with a specific user:

$ getent group | grep username
share|improve this answer
I found that there is a user named speech-dispatcher that belongs to group audio (based on groups speech-dispatcher). But it is not listed under getent group command! What is the problem? – PHP Learner Sep 15 '15 at 3:07
@PHPLearner If you have another question, please post a question, not a comment. – EEAA Sep 15 '15 at 3:08
for user in $(awk -F: '{print $1}' /etc/passwd); do groups $user; done

cat /etc/group | awk -F: '{print $1, $3, $4}' | while read group gid members; do
    members=$members,$(awk -F: "\$4 == $gid {print \",\" \$1}" /etc/passwd);
    echo "$group: $members" | sed 's/,,*/ /g';
share|improve this answer
While that would probably work, it seems a bit overly complicated, doesn't it, when there are perfectly good simple one-shot commands to do this? – EEAA Jan 31 '12 at 4:41
It certainly wouldn't get anything that lives in a centralized repository. And that's definitely information that you'd want to see. – Magellan Jan 31 '12 at 23:50

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.