User Groups in Linux – POFTUT

User Groups in Linux


I have heard that Linux have groups. I wonder that how can use groups in Linux ? Linux user groups are used to groups users so for privilege and permission issues can be solved for multiple users easily. For example if we have a file and want to read access for 47 Linux users we can use groups mechanism to group these users and give access to the newly created group.

List Current User Groups

First thing we will do is listing user groups in a Linux system. We can list current user group like below

$ groups
List Current User Groups
List Current User Groups

We can see that current user is joined groups like ismail adm sudo etc.

List All Groups

But if we want to list all groups those exists in Linux system we can use following command.

$ sudo cut -d: -f1 /etc/group
List All Groups
List All Groups

Create Group

We can create new group to add user. New group creation can be done like below.

$ sudo groupadd test
  • We have added group named test

Remove Group

Removing an existing group can be done with groupdel method.

$ sudo groupdel test
  • Remove group named test

Group File

Group file is the database used by groups. Actually it is a text file like below.

$ cat /etc/group
Group File
Group File
  • And it is generally resides in /etc/group 
  • For the first like root is group name
  • is the password where it is stored in /etc/gshadow
  • is the group id

Add User To the Group

We can add existing user to the existing group  by using usermod command

$ sudo usermod  -a -G root ismail
  • usermod -a is command to add user to group
  • -G root is used to specify group
  • ismail is the user name
LEARN MORE  How To Set or Change User Password In Linux?

Remove User From Group

We can remove existing user to the existing group  by using usermod command

$ sudo usermod -G root ismail
  • usermod  is command to remove user from group
  • -G root is used to specify group
  • ismail is the user name

Leave a Comment