10 - Linux Groups

What are Linux groups ?

A group is a set of users, created to share files and to facilitate collaboration. The system administrator can add new groups and give users membership to the different groups, according to the users' organizational needs. On a Linux system, you're always a member of at least one group.

Groups are used in Linux for access control. The only user that has full access is the super user (ROOT).

Where we can find the group information ?

The /etc/group is the file that defines the groups on the system.

To display the group of a user we will use the command :

    bash:>
    groups "user name"

- if we do not use the "user name" option the current user group will be displayed.

How to create a new group in Linux

To create a new group we will use the "groupadd" command :

    bash:>
    groupadd "group name"

How can we add a new member to a group in Linux

For this we will use the "gpasswd" command :

    bash:>
    gpasswd [option] "user name" "group name"

Option

Except for the -A and -M options, the options cannot be combined.

The options which apply to the gpasswd command are:

  • [-a] -add user - Add the user to the named group
  • [-d] -delete user - Remove the user from the named group
  • Examples

      bash:>
      gpasswd -a user1 group1

    - this command will add the user named "user1" to the group named "group1".

      bash:>
      gpassw -d user1 group1

    - this command will remove the user named "user1" from group named "group1". But will not delete the user.

    How drop/delete a group in Linux

    For this we will use the "groupdel" command :

      bash:>
      groupdel "group name"

    - the group has to exist in order to drop it :).

    How to give permissions to groups in Linux

    After a group is created it has no permissions on anything so we need to create some for them.

    For this we will use the "groupmod" command :

    The groupmod command modifies the definition of the specified GROUP by modifying the appropriate entry in the group database.

    groupmod - modify a group definition on the system

    Syntax

    bash:> groupmod [options] "group name"

    Options

  • [-h] - Display help message and exit.
  • [-n] - Change name of a group.
  • Example

      bash:>
      groupmod -n group1 groupX

    - this command will change the name of the group "group1" to "groupX".

    For now this all about groups, in future tutorials we will go in more details about groups and how to set out default groups.