Highlights
📌 Groups in Linux are collections of users used to manage permissions, collaboration, and security.
📌 Two types of groups:
▪️ Primary group – assigned automatically, usually the user’s own group.
▪️ Secondary groups – additional groups granting extra privileges.
📌 Why groups matter: they simplify user management, enable controlled resource access, improve collaboration, and enforce security policies.
📌 Ways to list groups in Linux:
▪️ View /etc/group
file directly.
▪️ Use commands like getent
, cut
, awk
, groups
, id
, and lid
.
▪️ Extract information from /etc/passwd
or /etc/gshadow
.
▪️ Filter results with grep
or combine tools for custom output.
▪️ GUI tools like system-config-users
provide a graphical approach.
📌 Pro tip: Use the right command depending on whether you want all system groups, user-specific groups, or formatted outputs.
Linux provides its users with a robust and flexible environment. As they explore this vast landscape, understanding user groups becomes essential. Groups play a critical role in managing permissions, facilitating collaboration, and maintaining a secure and organized system.
In this blog, we will explore the available methods and commands to list all groups in Linux, offering valuable insights to both novices and veteran users.
If you are someone who prefers learning in an audio visual format; do checkout the below YouTube video.
Groups in Linux
In Linux, groups are the collections of users with their permissions to the system, and this information is stored at /etc/group. In this file, you’ll find details such as group names, encrypted passwords, group identification numbers, and user names.
There are two types of groups a user can join:
- Primary or login group: This is the group assigned to files created by each user, typically their name being their primary group designation. Each user belongs to exactly one primary group.
- Secondary or supplementary group: This group grants privileges to specific users. Each user may belong to zero or more secondary groups.
Before we dive into the techniques for listing groups, let's briefly explore why groups matter in the Linux ecosystem.
For visual learners, we've created this comprehensive video overview:
The Importance of Groups in Linux
Below are some of the tasks that Linux relies on groups to accomplish:
User Management
Groups simplify user management by grouping users with similar roles or responsibilities. They allow administrators to apply permissions collectively to a group of users.
Resource Access
Groups facilitate controlled access to files, directories, and system resources. Permissions can be assigned at the group level, ensuring efficient resource management.
Collaboration
Groups enhance collaboration by enabling users with shared objectives to work seamlessly. Group memberships streamline the process of granting access to shared project files.
Security
Security policies can be enforced at the group level, ensuring a granular approach to system security. Group-based permissions contribute to a secure and well-organized Linux environment.
To learn more about permissions in Linux, check out this blog:

Methods to List All Groups in Linux
Now, let's explore the various methods and commands available to list all groups in a Linux system.
Using the /etc/group File
In Linux, group information is stored in the /etc/group file. This file contains details about each group, such as the group name, group password (usually 'x' indicating that the password is stored in the /etc/gshadow file), group ID (GID), and a list of users who belong to that group.
To view the content of the /etc/group file, you can use the cat or less command:
cat /etc/group
Listing Groups with the getent Command
getent, short for "get entries," is a Linux command for viewing the contents of system information files, also known as databases, on Linux. /etc/group, /etc/passwd, and /etc/shadow files are good examples of such databases.
Using Linux's getent command to view user group information is simple. Just type getent
followed by the filename you wish to examine. To list all groups on a Linux system using getent, use the following command:
getent group
The output of getent group
will be slightly different from the cat /etc/group
command. This is because getent pulls group information from other similar databases on your system (LDAP, for example).
This command provides a neat list of all groups along with their details, making it a versatile tool for group enumeration.
Using the cut Command for Group Listing
If you prefer a more concise output, you can use the cut command to filter the relevant information. For instance, to display only group names and GIDs, run the following command:
getent group | cut -d: -f1,3
This command uses the -d
option to specify the delimiter (colon : in this case) and the -f
option to select specific fields.
Utilizing the awk Command for Group Information
The awk
command is a powerful text processing tool. You can leverage it to extract and format group information. For instance, to display group names and the number of users in each group, you can use:
getent group | awk -F: '{print $1, ":", NF-3, "users"}'
Here, -F
specifies the field separator, and NF-3
calculates the number of users in the group.
Combining cut and awk for Customized Group Listing
Combining cut
and awk
can provide a customized and succinct group listing. For example:
getent group | cut -d: -f1,3 | awk '{print "Group:", $1, "GID:", $2}'
This command extracts group names and GIDs, then formats and displays the information.
The groups Command for User-specific Groups
If you want to know which groups a specific user belongs to, you can use the groups
command. For instance:
groups username
You can replace the username with the actual username, and the command will display a list of groups associated with that user.
Using the lid Command
The lid
command (Linux User and Group Information) is a user-friendly tool to list user and group information. To display all groups, run:
lid -g
This command provides a concise list of groups, along with their GIDs and member users.
Leveraging the awk Command with /etc/passwd
While unconventional, you can use the /etc/passwd file to indirectly obtain group information. The awk
command helps filter and display group data:
awk -F: '{print $4}' /etc/passwd | tr ',' '\n' | sort -u
This command extracts the fourth field (group GID) from /etc/passwd, splits comma-separated values, and sorts them to display unique group IDs.
Using cut and sort Commands with /etc/passwd
A similar approach involves cut and sort to extract and organize GIDs from the /etc/passwd file:
cut -d: -f4 /etc/passwd | sort -u
This command extracts and displays unique group GIDs from /etc/passwd.
Using awk with /etc/gshadow
The /etc/gshadow file contains shadowed information about group accounts. You can use awk to extract group names.
awk -F: '{print $1}' /etc/gshadow
This command extracts and displays group names from the /etc/gshadow file.
Listing Groups with grep for Specific Patterns
You can filter groups based on specific patterns using the grep command. For example, to list groups starting with the letter 'a', you can use:
getent group | grep '^a'
This command uses the caret ^
to match the beginning of a line.
Using the ‘id’ command
Linux id command provides information about an individual's identity, including user and group IDs. The -nG
option of the id command can be used to view which groups a user belongs to. If the username is omitted, it shows information for the current user.
If you would like information on the user Osboxes, for instance, run this command:
id osboxes
This command displays the user ID (uid), primary group (gid), and any secondary groups associated with the user.
Below is the output:
uid=1001(osboxes) gid=1001(osboxes) groups=1001(osboxes),27(sudo)
Use the -n
option to display only names instead of numbers, while options -g
will display only primary groups, and -G
will list all groups.
The following command will display all of the groups to which a user belongs:
id -nG
The use of the id command offers an efficient and quick way of gathering user membership details directly from the command line, making it useful for administering and troubleshooting Linux systems.
Using Compgen Command
The compgen
command in Linux is typically used for the auto-completion of commands, but it doesn't directly list group files. Instead, you can use compgen
in combination with other commands, such as ls
and grep
, to achieve the desired result.
Here's an example of how you can use compgen
to list group files in Linux:
compgen -G /etc/group*
-G
: This option of compgen is used to generate a list of group names.
/etc/group*
: This specifies the pattern for the group files. The asterisk (*) is a wildcard character that matches any characters.
However, note that this method assumes that group files are located in the /etc/ directory and follow the standard naming convention, which is /etc/group. If your group files are located elsewhere or have different names, you may need to adjust the pattern accordingly.
Graphical User Interface (GUI) Tools for Group Management
For users who prefer a graphical approach, various Linux distributions provide GUI tools for managing users and groups. Tools like system-config-users or user-settings (varying by distribution) provide a user-friendly interface for group management.
These methods provide flexibility in obtaining group information based on the specific details you need. Choose the approach that best fits your requirements or combine commands for more advanced queries.
Remember to use commands with appropriate permissions (e.g., use sudo for commands that require elevated privileges) and consider the security implications of accessing certain files or databases.
Check out this blog to learn more about Linux files & directories:

Conclusion
In conclusion, understanding how to list all groups in Linux is essential for effective user and permission management. Whether you prefer command-line tools like getent, cut, and awk, or you opt for GUI tools, the ability to navigate and comprehend Linux groups enhances your system administration skills.
By exploring these methods, you gain valuable insights into Linux group management, empowering you to administer systems more efficiently. As you continue your journey in Linux administration, these skills will prove invaluable for maintaining a secure and well-organized computing environment.
To learn more about Linux, check out our hands-on Linux course.
Here is a learning path for those who want to get started with Linux and eventually become a practitioner.

FAQs: Listing and Managing Groups in Linux
Q1. How do I list all groups on a Linux system?
Use any of the following:
getent group
cat /etc/group
cut -d: -f1 /etc/group | sort
getent
is preferred because it respects NSS sources (e.g., LDAP, SSSD, NIS), not just local files.
Q2. What’s the difference between getent group
and cat /etc/group
?
cat /etc/group
shows only local groups.getent group
queries all configured identity sources (LDAP/SSSD/NIS + local), giving you the authoritative view in enterprise setups.
Q3. How can I list only group names (without GIDs and members)?
- To list only group names:
getent group | cut -d: -f1
- To include GIDs as well:
getent group | cut -d: -f1,3
Q4. How do I see which groups a specific user belongs to?
id -nG <username>
groups <username>
To include numeric IDs:id <username>
Q5. How do I find a group’s members?
Run: getent group | awk -F: '{n=split($4,a,","); if($4=="") n=0; print $1 ": " n " users"}'
This handles empty member lists cleanly.
Q7. How do I list groups that match a pattern (e.g., start with “dev”)?
getent group | grep '^dev'
- For case-insensitive search:
getent group | grep -i '^dev'
Q8. What’s the safest way to script a group list for automation?
Use getent
for portability:
#!/usr/bin/env bash
set -euo pipefail
getent group | cut -d: -f1 | sort | uniq
Tip: Avoid parsing /etc/group
directly in environments with centralized identity (LDAP
/SSSD
).
Q9. Why does getent group
show groups I don’t see in /etc/group
?
Because those groups are coming from remote identity providers (e.g., LDAP via SSSD).
Your system’s /etc/nsswitch.conf
determines lookup order and sources.
Q10. How do I list a user’s primary vs secondary groups?
- Primary group name:
id -gn <username>
- Primary group numeric ID:
id -g <username>
- All groups including secondary:
id -nG <username>
Q11. What if I get “Permission denied” reading /etc/gshadow
?
/etc/gshadow
is restricted to root for security.
Prefer getent group
, or use sudo
to read it when absolutely necessary.
Q12. How can I list groups inside a container (Docker/Podman)?
Exec into the container and run:
docker exec -it <container> getent group
docker exec -it <container> cat /etc/group
Note: minimal images may lack getent
. In that case, install glibc
/libnss
tools or inspect mounted files.
Q13. Is there a GUI way to view/manage groups?
Yes—Linux distros provide tools like Users & Groups, system-config-users
, or *Settings → Users`.
For servers, CLI is preferred because it is faster and scriptable.
Q14. How do I export all groups and members to CSV?
Run:getent group | awk -F: '{if($4=="") members=""; else members=$4; print $1","$3","members}' > groups.csv
This produces a CSV file with columns: group_name, GID, members
.
Q15. What are best practices for group management at scale?
- Use role-based groups (per app or team) instead of user-specific ACLs.
- Automate via configuration management (
Ansible
,Chef
,Puppet
) or directory services (LDAP
,SSSD
). - Audit regularly: export and diff group membership in CI pipelines.
- Restrict access to
/etc/gshadow
and avoid storing sensitive information in group descriptions.
Discussion