Overview
In Linux, access permissions for files and directories are managed not only at the user level but also at the group level. The `groups` command is a simple tool that shows at a glance which groups a user belongs to. This information helps easily determine if a user can access resources permitted only to specific groups. `groups` outputs the same result as the `id -Gn` command and is primarily used to check permission issues or group memberships.
Key Features
Key features of the `groups` command include:
- Prints the names of groups that the current user or a specified user belongs to.
- Provides a simple way to check a user's group membership.
- Returns the same results as the `id -Gn` command.
- A simple command with very few options.
Group Membership
A user can belong to multiple groups. `groups` outputs all groups a user is a member of.
- Primary Group: The group automatically assigned when a user is created. It usually has the same name as the username.
- Supplementary Groups: Additional groups assigned to a user. Through these groups, a user gains access permissions to specific resources.
Key Options
The `groups` command is very simple, mainly using basic help options like `--help` or `--version`.
1) Output Options
2) Help
Generated command:
Try combining the commands.
Description:
`groups` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Learn the functionalities of the `groups` command through various usage examples.
Check Current User's Group List
groups
Prints the names of all groups the current logged-in user belongs to.
Check a Specific User's Group List
groups www-data
Checks the names of groups that the system user `www-data` belongs to.
Check Current User's Group List along with UID/GID
id
Uses the `id` command to check group information along with UID and GID.
Installation
The `groups` command is part of the `coreutils` package and is included by default in most Linux distributions. No separate installation is required.
Tips & Cautions
Important points to note when using the `groups` command are summarized here.
Tips
- The `groups` command outputs the same result as `id -Gn`. The `id` command also shows Group ID (GID) information, providing more detailed information.
- After adding a user to a new group, the user must log in again for the changes to take effect. You can also use the `newgrp` command to activate new group permissions immediately in the current shell.