Understanding Group Memberships
In Linux, every user belongs to one or more groups. These groups help manage permissions and access to files and directories. In this step, you will learn how to view group memberships for yourself and other users.
Checking Your Current Working Directory
First, let's make sure you are in the correct working directory:
cd ~/project
Viewing Your Group Memberships
To see which groups your current user account belongs to, you can use the groups
command without any arguments:
groups
This command will display a list of all groups that your user account is a member of. The output will look similar to this:
labex sudo ssl-cert public
In this example, the user labex
is a member of the groups labex
, sudo
, ssl-cert
, and public
.
Viewing Group Memberships for Other Users
To view the groups that another user belongs to, you can specify the username as an argument to the groups
command:
groups username
For example, to see which groups the root
user belongs to, you would run:
groups root
This will display an output similar to:
root : root
This shows that the root
user is only a member of the root
group.
Why Group Membership Matters
Group membership determines what files and directories a user can access. When you set permissions for a file or directory, you can specify different access levels for the owner, the group, and others.
For instance, if a file has read permissions for a specific group, all users who are members of that group can read the file, even if they are not the owner.
Please make sure you have run both the groups
and groups root
commands at least once to proceed to the next step.