Linux Show All Members of a Group Command

/etc/group

ADVERTISEMENTS



Linux Show All Members of a Group Commands

Tutorial details Difficulty Easy (rss) Root privileges Yes Requirements None Time 1m /etc/group file – User group file members command – List members of a group lid command (or libuser-lid on newer Linux distros) – List user’s groups or group’s users

I am a new Linux user and created a couple of groups on the server. I need to find out all members of a group called “ftponly”. How do I list all members of a group on Linux or Unix-like systems?Thefile is a text file that defines the groups on the Linux and Unix based systems. You can simply query this file to find and list all members of a group.

There are two types of groups in Linux:

Primary group – is the main group that is associated with user account. Each user is a member of exactly one primary group.

Secondary group – used to provide additional rights to user. For example, access to the dvd/cdrom drive can be granted with help of cdrom group.

Linux: List all members of a group using /etc/group file

Use the grep command as follows:

$ grep 'grpup-name-here' /etc/group

$ grep 'ftponly' /etc/group

$ grep -i --color 'ftponly' /etc/group

ftponly:x:1001:raj,vivek,archana,sai,sayali

To get just a list of all members of a group called ftponly, type the following awk command:

awk -F ':' '/ftponly/{print $4}' / etc / group # list all members of sudo group in linux # awk -F ':' '/sudo/{print $4}' / etc / group awk -F':' '/ftponly/{print $4}' /etc/group # list all members of sudo group in linux # awk -F':' '/sudo/{print $4}' /etc/group

Display group memberships for each Linux user

Want to see group memberships for each given USERNAME under Linux? The syntax is as follows for the groups command:

groups

groups {USERNAME}

groups vivek

The following outputs indicates that the user named ‘vivek’ is part of four groups including ‘vivek’ primary group:

vivek : vivek wheel lxd vboxusers

Linux List all members of a group using members command

Warning: members command is not installed on most Linux distros. Use yum command or apt-get command/apt command to install the same:

$ sudo apt-get install members

To outputs members of a group called ftponly, enter:

$ members {GROUPNAME}

$ members ftponly



How to list all users in a Linux group using lid command

In this example the members command displays a space-separated list of group member names on screen.

You can displays information about groups containing user name, or users contained in group name using lid command as follows.

Warning: lid command is not installed on most distros. Use yum command or apt-get command to install the same:

$ sudo apt-get install libuser

To see users contained in group named ‘ftponly’:

# lid -g ftponly

Please note that newer version of libuser renamed the lid command to libuser-lid . Thus, use it as follows:

$ sudo libuser-lid -g ftponly

Sample outputs:

raj(uid=1001) vivek(uid=1002) archana(uid=1003) sai(uid=1004) sayali(uid=1005)

To show information about groups containing user named ‘nixcraft’:

Use lid command or libuser-lid command on Linux to show all members of a group named nixcraft:

# lid nixcraft

OR

$ sudo libuser-lid nixcraft

Sample outputs:

adm(gid=4) cdrom(gid=24) sudo(gid=27) dip(gid=30) plugdev(gid=46) lpadmin(gid=109) nixcraft(gid=1000) sambashare(gid=124)

See lid command man page for more information.

How to list groups in Linux

To see all users, run less command/more command:

less /etc/group

OR

more /etc/group

Another option is to type the following getent command:

getent group

For example, locate the members of a group with the name vboxusers, run:

getent group vboxusers

Sample outputs indicating vivek and raj users are part of vboxusers group:

vboxusers:x:976:vivek,raj

Finally, you can use the id command to display real and effective user and group IDs:

id

id vivek

id -nG raj # show all group IDs for raj user

id -ng raj # show only effective group ID for raj user

Conclusion

Now you know how to use various Linux commands to show all members of a group. I suggest you read the man pages for more info by typing the following man command:

$ man libuser-lid $ man members