How do I Find Out Users in a Group?

In Linux, a user is an account that is used to interact with the operating system and its resources, while a group is a collection of one or more users who share the same permissions to access files, directories, and other system resources. It provides a way to manage permissions and access control for resources on the system. 

This article will explain different methods to find out which users are part of a group in Linux.

Method 1: Using the “groups” Command

The “groups” command is utilized to display the user which is associated with any group or not. To find the members of a specific group, users must specify the user name. In our case, specify the “roger” as username in the following command:

$ groups roger

The output shows that the user “roger” is a part of the “itslinuxfoss” group.

Method 2: Using the “getent” Command

The “getent” command is utilized to retrieve information from databases that are supported by the system, including group information stored in the “/etc/group” file. To find the members of a specific group, users specify the name of the group, such as “itslinuxfoss” in the following command:

$ getent group itslinuxfoss

The output shows the name of the user “roger” in a group “itslinuxfoss”.

Method 3: Using the “/etc/group” File 

The “/etc/group” file contains information about groups on the system, including the name of the group and the group ID (GID). To find the members of a specific group, open the “/etc/group” file in a text editor and search for the group name by executing the below command:

$ sudo nano /etc/group

The output displays the group names with their GIDs, separated by colons. In this way, users can find out which users are in a group, such as “roger” is a group member of “itslinuxfoss”.

Method 4: Using “id -Gn” Command

To check out the user of a specified group, users can utilize the “id” command with the “-Gn” option by specifying the name of the user. For instance, “roger” is specified as a username:

$ id -Gn roger

The execution of the above command presents the user  “roger”, which is associated with the group “itslinuxfoss”.

Conclusion

To find out which users are in a group, users can utilize the “groups”, “getent”, and “id -Gn” commands in Linux. Also, the “/etc/group” file contains information on group names with their associated GID that can be displayed via the Nano editor. This article has explained all possible methods to find out which users are in a group within Linux.