186

How can I see all the members of a group in Linux?

Flyk
  • 1,480
  • 3
  • 18
  • 24
fratrik
  • 2,645
  • 3
  • 19
  • 11

3 Answers3

217

Use the commands:

getent group groupname

or

getent group groupname | awk -F: '{print $4}' |  tr "," " "
alper
  • 232
  • 5
  • 21
us3r
  • 2,577
  • 1
  • 14
  • 9
  • 1
    So to add group, add user to group, change permissions of folder to group, and get all members of group, you would run the following commands respectively: addgroup programmers adduser donato programmers chown -R root:programmers idea-IU-141.1010.3 getent group programmers – Donato Jun 09 '15 at 04:56
  • chmod -R g+w idea-IU-141.1010.3 – Donato Jun 09 '15 at 05:14
  • Interesting find, "getent groups" (without any group specified) and "cat /etc/group" both give exactly the same output, at least on my system. – okolnost Oct 04 '16 at 22:43
  • This answer is not really complete. `members ` probably gives more what the OP is looking for. The difference is explained here [Link](https://askubuntu.com/a/1271766/597223) – RichEarle Aug 19 '22 at 15:04
32

You can do

members YOUR_GROUP_NAME

and it will list all the users in the group YOUR_GROUP_NAME.

If it's not installed by default:

sudo apt-get install members
vvvvv
  • 488
  • 8
  • 20
anonymous
  • 321
  • 3
  • 2
19

One more way to check all the members of a group is by checking the /etc/group file which lists all the groups and its members

Example:

root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:syslog,nikhil
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
kmem:x:15:
dialout:x:20:
fax:x:21:
voice:x:22:
cdrom:x:24:nikhil
floppy:x:25:
tape:x:26:
sudo:x:27:nikhil
audio:x:29:pulse

The first string (separated by :) specifies the group name and the last string specifies the user added to this group.

Nikhil Katre
  • 291
  • 2
  • 3