In Linux, Users can be listed in groups. Groups allow you to set permissions on the group level instead of having to set permissions for every individual user. In this guide, we will see how to get the advantage of using groups in our Linux system.

Groupadd

Groups can be created with the groupadd command. The example below shows the creation of five (empty) groups

group file

Users can be a member of several groups. Group membership is defined by the /etc/group file

The first field is the group’s name. The second field is the group’s (encrypted) password (can be empty). The third field is the group identification or GID. The fourth field is the list of members, these groups have no members.

groups

A user can type the groups command to see a list of groups where the user belongs to.

usermod

Group membership can be modified with the useradd or usermod command.

Be careful when using usermod to add users to groups. By default, the usermod command will remove the user from every group of which he is a member if the group is not listed in the command! Using the -a (append) switch prevents this behaviour.

Groupmod

You can change the group name with the groupmod command.

Groupdel

You can permanently remove a group with the groupdel command.

gpasswd

You can delegate control of group membership to another user with the gpasswd command. In the example below we delegate permissions to add and remove group members to john for the admingroup1 group. Then we login as john and add paul to the admingroup1 group.

Group administrators do not have to be a member of the group. They can remove themselves from a group, but this does not influence their ability to add or remove members.

Information about group administrators is kept in the /etc/gshadow file.

To remove all group administrators from a group, use the gpasswd command to set an empty administrators list.

The following two tabs change content below.
Ruwantha Nissanka is a Professional Cyber Security Engineer from Sri lanka with having a demonstrated history of providing cyber security services for multiple organizations in Sri Lanka. He is a positive person who wants to believe the best in others and he likes to help, encourage people and make them feel good.