How to Use the Linux groups Command to View User Group Memberships

In Linux, file access, execution privileges, and security boundaries are largely governed by the group system. Every user belongs to at least one primary group and can be added to multiple secondary groups to grant them access to specific directories, hardware devices, or administrative commands (like sudo).

When troubleshooting permissions errors—such as a user being denied access to a shared directory or failing to execute a privileged command—the first step is to verify their group memberships. The simplest and most direct way to do this in the Linux terminal is by using the groups command.

How to Check Your Own Group Memberships

If you want to see which groups the currently logged-in user (you) belongs to, you do not need to provide any arguments.

Simply open your terminal and type:

groups

The output will be a single line displaying the names of all the groups associated with your user account. For example, if you run this on a typical Ubuntu installation, you might see:

johndoe adm cdrom sudo dip plugdev lpadmin lxd sambashare

The first group listed (johndoe) is usually the user’s primary group, which is created automatically when the user account is generated. The subsequent groups are secondary groups that grant specific system privileges. For instance, membership in the sudo group means this user is allowed to execute commands with root privileges.

How to Check Another User’s Group Memberships

System administrators frequently need to verify the permissions of other users without logging into their accounts. You can check any user’s group memberships by simply passing their username as an argument to the command.

For example, to check which groups a user named sarah belongs to, type:

groups sarah

The output will clearly indicate the username followed by a colon and the list of their groups:

sarah : sarah developers www-data

In this scenario, Sarah is part of her own primary group, a developers group (perhaps for accessing shared code repositories), and the www-data group (which allows her to manage web server files).

Checking Multiple Users Simultaneously

The groups command accepts multiple usernames at once, making it easy to compare permissions across a team.

To check the groups for three different users simultaneously, separate their usernames with a space:

groups johndoe sarah miket

The terminal will output the memberships line by line:

johndoe : johndoe sudo
sarah : sarah developers www-data
miket : miket developers

Alternative: Using the id Command

While the groups command provides a clean, easy-to-read list of group names, it does not provide the numerical Group IDs (GIDs), which are sometimes required for advanced bash scripting or when modifying system configuration files.

If you need the GIDs alongside the group names, use the id command instead.

To check your own user details, type:

id

The output will display your User ID (UID), primary Group ID (GID), and a detailed breakdown of all secondary groups including both their names and numerical IDs:

uid=1000(johndoe) gid=1000(johndoe) groups=1000(johndoe),4(adm),24(cdrom),27(sudo)

Just like the groups command, you can append a username to check someone else’s details (e.g., id sarah).

Troubleshooting: Missing Group Memberships

If you use the usermod -aG command to add yourself to a new group (for example, adding yourself to the docker group so you can run containers without sudo), running the groups command immediately afterwards might not show the new group.

This is because group memberships are evaluated at the moment you log in. If you modify your own groups during an active session, the current terminal shell is unaware of the change.

To fix this and force the system to apply your new group memberships immediately without requiring a full system reboot or graphical log out, use the su (substitute user) command to start a new login shell for yourself:

su - yourusername

After entering your password, run the groups command again, and the newly added group will now be visible and active.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.