Discover how to display your Linux Group, understand user permissions, and master group management. This in-depth guide explores commands like id, groups, and whoami, delves into file ownership, and provides best practices for securing your system. Whether you are a novice user or a seasoned administrator, you will find everything you need to know about viewing and managing your groups, permissions, and advanced security settings.
Linux is a powerful multiuser operating system that efficiently manages users, groups, and a well-structured permissions model. Understanding how groups work and how to display your group memberships empowers you to control file access, collaborate effectively, and maintain a secure environment.
Every Linux user belongs to at least one group, typically called the primary group. Many users also belong to additional groups called supplementary groups. System administrators can easily grant or restrict permissions across multiple users by grouping users requiring similar access levels.
Key topics in this guide include:
With these topics in mind, you will develop a deep understanding of how Linux’s permission system operates, how to check your privileges, and how to configure secure access for others.
Linux’s multi-user capability relies on numerical identifiers known as User IDs (UIDs) and Group IDs (GIDs). Each user on a Linux system is assigned a unique UID, and a GID identifies every group.
Whenever a user logs in, the system checks /etc/passwd for the user’s UID and primary GID and references /etc/group for supplementary groups. This mechanism ensures the system knows which resources each user can access.
A user’s primary group is the default group assigned to them, usually specified in /etc/passwd. Beyond that, users can belong to multiple supplementary groups. For instance, a user might be part of a developers group for programming tasks, a docker group to run Docker commands, and an admin group for administrative privileges.
These group memberships help streamline permissions management. Instead of granting access to individual users one by one, administrators can assign or revoke privileges for an entire group, making the process more efficient.
Correctly configuring these files is essential to maintaining a secure and well-organized system. The kernel relies on these files to identify who owns which processes and files.
UIDs and GIDs form the bedrock of Linux’s security model. Misconfigurations can inadvertently grant unauthorized access or block legitimate users. By carefully assigning UIDs and GIDs, you ensure that every file, process, and resource is accessed only by those who should have access. This foundation sets the stage for effectively viewing your groups and managing file permissions.
Understanding your current group memberships is crucial for troubleshooting permissions or verifying proper access. Linux offers several commands to display this information.
The id command is one of the most comprehensive tools for identifying your user and group affiliations. Simply type:
id
You will see output like this:

uid=1001(john) gid=1001(john) groups=1001(john),10(wheel),1002(developers)
If you have the necessary privileges (such as root access or sudo rights), you can also check another user’s group memberships:
id username
The group’s command provides a concise list of the groups you belong to. Type:
groups

You might see:
john wheel developers
The first name (john) is your primary group, and the remaining names (wheel, developers) are your supplementary groups. To check another user’s groups:
groups username
While whoami does not list group memberships, it tells you the current username of the shell you operate in. For example:
whoami
Output might be:

john
This command is convenient if you switch users via su or sudo su – and must verify which user is active.
You can manually inspect /etc/group or use the getent command for more detailed verification:
cat /etc/group | grep john

or
getent group developers

The first method directly searches for lines matching “john” in /etc/group, while the getent approach fetches group information from system databases (including remote services like LDAP if configured).
By mastering these commands, you will quickly determine your group memberships or those of other users, streamlining tasks like file sharing and permission troubleshooting.
Groups in Linux are closely tied to file permissions. When you run ls -l in a directory, you might see:

-rw-r--r-- 1 john developers 4096 Sep 1 12:00 example.txt
Let’s break down the components:
The string -rw-r–r– is divided into three sections for owner, group, and others:
The leading – indicates a regular file (a d would indicate a directory).
Group ownership becomes critical when multiple users need similar file access. By assigning the developers group to example.txt, everyone in that group can read the file (as determined by the group permission bits). This is a more efficient method than assigning permissions to individual users.
Use chmod to modify file permissions. There are two main approaches:
Symbolic mode:
chmod g+w example.txt

This grants write permission (+w) to the group (g).
Numeric (octal) mode:
chmod 640 example.txt

Here, 640 translates to:
After using chmod, run ls -l again to confirm that the changes took effect. This verification step helps catch typos or mistakes.
Directory permissions slightly differ in their meaning:
For group-shared directories, set the group ownership to the relevant group and configure the right combination of read, write, and execute bits.
Beyond basic file permissions, you must also know how to manage file ownership and group memberships. Two commands, chown (change ownership) and chgrp (change group), are crucial.
To change the owner (user) of a file:
sudo chown newowner example.txt

To change both the owner and group simultaneously:
sudo chown newowner:newgroup example.txt
Appending the -R flag applies changes recursively to all files and subdirectories:
sudo chown -R newowner:newgroup /path/to/directory

Use this with caution to avoid breaking essential system directories.
If you only need to change the group:
sudo chgrp developers example.txt

The -R flag also works for recursive group changes:
sudo chgrp -R developers /path/to/directory
To create a new group:
sudo groupadd developers

To delete a group:
sudo groupdel developers

Ensure no critical files or active users rely on the group before deleting it.
It’s possible to include a user in a group that already exists with usermod:
sudo usermod -aG developers john

You create a well-organized environment and avoid security lapses by diligently managing ownership and groups.
Linux offers more than just standard read, write, and execute bits. You can also use SetUID, SetGID, and the sticky bit for specialized situations.
When the SetUID bit is set on an executable, users who run that program temporarily gain the file owner’s privileges. A classic example is the passwd command, which requires root-level access to modify system passwords.
To set the SetUID bit:
sudo chmod u+s /usr/local/bin/customscript

Use SetUID carefully; a misconfigured script can become a security risk, allowing privilege escalation.
When set on an executable, SetGID makes the program run under the file’s group privileges. When set on a directory, any new file within inherits the directory’s group ownership, a common practice for shared-team directories.
sudo chmod g+s /var/shared

The sticky bit prevents users from removing or renaming files they do not own in a shared directory. For example, /tmp is world-writable but uses the sticky bit to stop users from altering each other’s files.
sudo chmod +t /var/shared
When you list files with ls -l, you might see letters like s or t instead of x:
To customize your system’s security and collaboration model, implement these advanced settings wisely.
Traditional Unix permissions cover most use cases, but sometimes you need even more fine-grained control. Access Control Lists (ACLs) let you assign specific permissions to individual users or groups, regardless of traditional ownership.
First, ensure that your filesystem supports ACLs. Modern file systems like ext4, xfs, and btrfs typically do. Sometimes, you must mount them with the acl option:
sudo mount -o remount,acl /dev/sda1 /mnt/data
Check your distribution’s documentation for precise steps.
Use getfacl to see the ACLs for a file or directory:
getfacl example.txt

Example output:
# file: example.txt
# owner: john
# group: developers
user::rw-
user:david:rw-
group::r--
mask::rw-
other::r--
This shows that David has explicit permission to read and write, even though he might not be part of the developer’s group.
Use setfacl to add ACL entries:
sudo setfacl -m u:david:rw example.txt
To remove an ACL entry:
sudo setfacl -x u:david example.txt
You can also set default ACLs on directories so that new files inherit specific ACL rules:
sudo setfacl -m d:u:david:rw /var/shared
This ensures that any new file created in /var/shared automatically grants david read-write access.
ACLs are ideal in organizations where multiple teams or users need distinct access levels to the same resources. However, beware of overcomplicating your permission structure. Regularly document and audit any ACL usage to keep permissions transparent and maintainable.
Effective permission management involves being vigilant about potential pitfalls. Below are common mistakes and best practices to keep in mind.
Adhering to these guidelines prevents headaches and security breaches, ensuring a stable and secure Linux environment.
Scenario: A development team needs to share resources in /srv/devprojects with read-write access for all team members but no access for outside users.
Create a group (if needed):
sudo groupadd devteam

sudo usermod -aG devteam alice
sudo usermod -aG devteam bob
sudo usermod -aG devteam charlie

sudo chown -R root:devteam /srv/devprojects

sudo chmod -R 2770 /srv/devprojects

The 2 sets the SetGID bit so new files inherit the devteam group.
770 ensures that only the owner (root) and devteam have full permission.
Scenario: The finance department stores confidential files in /srv/finance, accessible only to the finance team.
Create the finance group (if not existing):
sudo groupadd finance

sudo usermod -aG finance diana

sudo usermod -aG finance edward
sudo chown -R root:finance /srv/finance

sudo chmod -R 750 /srv/finance

Scenario: The marketing team has a shared directory /srv/marketing for their group. A non-marketing user (reportinguser) needs read access to a specific file without joining the marketing group.
Set base permissions:
sudo chown -R root:marketing /srv/marketing

sudo chmod -R 770 /srv/marketing
sudo setfacl -m u:reportinguser:r /srv/marketing/MonthlyReport.xls
Now reportinguser can read that file without gaining access to everything else.
Scenario: You want a publicly writable directory /srv/uploads, but users should only be able to delete their files.
Create the directory and set world-writable permissions:
sudo mkdir /srv/uploads
sudo chmod 777 /srv/uploads

sudo chmod +t /srv/uploads

Users can delete only their files in /srv/uploads with the sticky bit set.
These examples highlight how to apply Linux permission and group concepts in real-world scenarios, ensuring collaboration and security.
Linux’s permissions model is critical to any secure, multiuser environment. Knowing how to show your group memberships with commands like id and groups is the first step in understanding and troubleshooting permission-related issues. From there, managing file ownership and permissions with chmod, chown, and chgrp lets you precisely control access and maintain an organized system.
Advanced features like SetUID, SetGID, and the sticky bit enable specialized security scenarios, while Access Control Lists (ACLs) address the need for fine-grained permissions beyond traditional Unix ownership. By following best practices such as using groups effectively, employing the least privilege principle, and documenting ACL usage, you can protect sensitive data and keep your system running smoothly.
Mastering these tools and techniques equips you to navigate almost any permission challenge on a Linux system. Whether you are setting up team directories, securing finance files, or enabling public uploads, a firm grasp of Linux permissions underpins every aspect of system administration and security. With the proper knowledge, you can tailor your permissions model to fit your needs, balancing accessibility, collaboration, and robust protection for your data.

Vinayak Baranwal wrote this article. Use the provided link to connect with Vinayak on LinkedIn for more insightful content or collaboration opportunities