groups
Display a user's group memberships
TLDR
Print group memberships for the current user
Print group memberships for a list of users
SYNOPSIS
groups [OPTION]... [USERNAME]...
PARAMETERS
--help
Displays a help message and exits, providing information on command usage.
--version
Outputs version information about the groups command and exits.
USERNAME
Specifies the username for which to display group memberships. If omitted, the command defaults to displaying the group memberships for the current effective user.
DESCRIPTION
The groups command is a utility used to print the names of the primary and any supplementary groups that a specified user belongs to. When no username is provided, it defaults to displaying the group memberships for the current effective user. It's commonly employed to quickly verify a user's group affiliations, which is crucial for managing file permissions, access control, and troubleshooting. The information returned by groups is sourced from the system's configured user and group databases, such as /etc/passwd, /etc/group, or external Name Service Switch (NSS) sources like LDAP or NIS. The output is a simple, space-separated list of group names. For instance, running groups alice might yield alice users sudo docker, where alice is her primary group (if configured as such) and users, sudo, and docker are supplementary groups. The primary group is typically the one listed in the user's entry in /etc/passwd and is usually the first one shown by the command. Understanding group memberships is fundamental for ensuring correct access to system resources and performing privileged operations securely.
CAVEATS
The groups command only displays group names, not their numerical IDs (GIDs). For GIDs, use the id command. The information provided relies on the system's configured Name Service Switch (NSS) modules, meaning it can query local files, NIS, LDAP, or other sources configured in /etc/nsswitch.conf. The output format is a simple space-separated list, which might require additional parsing with tools like awk or cut for more complex scripting needs.
OUTPUT FORMAT
The groups command prints a space-separated list of group names to standard output. The primary group for the specified user is generally listed first, followed by any supplementary groups. For example, for a user testuser, the output might be testuser users docker.
PERMISSIONS
Any user can execute the groups command to inquire about the group memberships of any other user on the system. This information is generally considered publicly accessible for system administration and understanding user contexts, as it does not expose sensitive data like passwords or GIDs.
NAME SERVICE SWITCH (NSS) INTEGRATION
groups leverages the Name Service Switch (NSS) system to resolve user and group information. This allows it to retrieve data not only from local files (/etc/passwd, /etc/group) but also from centralized directories or network services like NIS or LDAP, depending on the system's configuration in /etc/nsswitch.conf.
HISTORY
The groups command is a fundamental utility that has been a part of Unix-like operating systems for many decades, typically bundled within the coreutils package on GNU/Linux systems. Its core functionality—to list a user's group memberships—has remained consistently simple and direct throughout its history. Its development has focused on robustness and adherence to system-wide user and group management standards, particularly its seamless integration with the Name Service Switch (NSS) to accommodate various identity management backends beyond local files.