On a Linux system, you can create multiple groups of your choice. However, some groups exist by default on your system. Each user of a Linux system belongs to one or more of these groups. Once a user gets associated with a certain group in Linux, the user becomes a member of that group. In this guide, we will talk about the three different methods of listing the members of a group in Linux.
Methods of Listing the Members of a Group in Linux
To list the members of a group in Linux, you can choose any of the three methods explained below:
Method # 1: Using the /etc/group File
This method helps display all the groups present on a Linux system with the members associated with each of these groups. To use this method, you will have to execute the following command:
$ cat /etc/group
This command will list down all the contents of the /etc/group file containing all the groups of the Linux system along with their associated members, as shown in the image below:
Method # 2: Using the Members Command
If you want to find out the members of a specific group in Linux, then you can install the “members” command with the help of the following command:
$ sudo apt-get install members
The installation of this command will display the results shown in the following image on the terminal:
Now, we will use this command to list down the members of a specific group in the following manner:
$ members nopasswdlogin
Here, “nopasswdlogin” is the name of the group whose members we wish to list down. You can see from the following image shown that “system2” is the only member or user who is associated with the specified group in our Linux system.
Method # 3: Using the Getent Command
In this method, we will be using the “getent” command for listing down the members associated with a specific group in the following manner:
$ getent group nopasswdlogin
This command will also display all the members associated with the specified group, i.e., “nopasswdlogin” in this case, as shown in the following image:
Conclusion
The methods discussed in this article are extremely useful for listing the members of a group in Linux. If you intend to list down all the groups and their associated members, then you can use the first method. However, if you only wish to list down the members of a particular group, then you can pick either the second or third method.