Manage groups in Linux

Groups in Linux is as name suggest collection of user. Each group has its unique group ID (GID). Groups are of two types i.e. primary group and supplementary group, each system is user is member of 1 primary group and zero or more supplementary group. The group information is stored in /etc/group and the respective passwords are stored in the /etc/gshadow file.  All information stored in /etc.As you must be aware a file is assigned separate read, write, and execute permissions for owner, group and everyone else.

Creating a group

groupadd command creates new group with default setting. To run this command you must have root privileges.

Syntax

groupadd group_name

groupadd command creates group add its details to /etc/group file.

Creating group with specific group ID

groupadd command can group with specific group ID by using switch –g. If there is clash of group ID i.e. group ID already exists , the command will give error.

Syntax

groupadd –g group_ID group_name

Set password for a group

To set or change password for a group, use command gpasswd followed by group name for which change is to be done.

Syntax

gpasswd group_name

Adding user to group

You can add user to a group by using command gpasswd with switch –a.

Syntax

gpasswd –a username groupname

Removing user from group

Similar to adding user you can remove a user from a group by using command gpasswd with switch –d.

Syntax

gpasswd –d username groupname

Removing a group

If you want to delete a group you can use groupdel command. This command deletes all entries for group from system files (/etc/group and /etc/gshadow).

Syntax

groupdel group_name