Creating and Managing Groups

Creating Managed Groups
  • To create managed groups, the command used is groupadd.

Modifying and Deleting Groups
  • To delete groups, use the command groupdel.

  • To modify groups, use groupmod.

Using the groupadd Command
  • The groupadd command by itself has limited options.

  • Syntax: groupadd <group_name>

Example

  • To create a group named "support":

    • Command: groupadd support

  • This command is generally sufficient for creating a group as other options are rarely used.

Adding Users to Groups
  • To make a user a member of a group, use the usermod command.

  • Syntax: usermod -a -G <group_name> <username>

  • Example: To add user "Linda" to the "support" group:

    • Command: usermod -a -G support Linda

Explanation of Options

  • -G: Refers to a new list of supplementary groups.

  • Implies that when using -G, the old list of groups is overwritten.

  • To retain existing group memberships while adding a new group, the option -a (append) must be used in conjunction with -G.

  • Usage together: Always use -a with -G to ensure no existing groups are removed.

Checking Group Membership
  • To check which users are members of a specific group, you can refer to the /etc/group file.

  • The best way to find a member of the group is by using the grep command.

  • Example: To check members of the "support" group:

    • Command: grep support /etc/group

Result

  • The output shows "Linda" as a member of the "support" group.

Primary vs Secondary Groups
  • Note that when checking the membership of the primary group, it will not appear in the results for the user.

  • Example:

    • To see groups associated with user "Linda":

    • Command: grep Linda /etc/group

  • The results display her belonging to the "Linda" group, but membership in the primary group does not show up in the secondary group listing.

  • This is because primary groups are essential and do not get listed in this method.

Summary
  • Commands listed above enable group creation, modification, and membership management in a Unix/Linux environment. It is important to understand the specific options available with these commands to properly manage users' group memberships without unintended deletions.