Unix or Linux Users are always listed in different groups.
Linux Group allow us to set permission on the group level instead of setting the permission on individual level. The Linux Group can help to manage permissions for users.
Command line tools and by vi or vigr depending upon the user’s experience.
Users should use vi or vigr to manage groups, It will do proper locking or changes in the file.
The groupadd command creates or adds a group in the system.
Sample syntax of :
$ sudo groupadd <groupName>
$ sduo groupadd students
The above example adds a group named students to the system.
The File for Group Information
The file /etc/group contains information about all groups in the system. To read the contents use:
$ cat /etc/group
Each line in the file signifies a single group. And each row has 4 columns. The description for the column from the left:
- group_name: The general name of the group
- password: The password of the group, generally empty.
- group_id (GID): The numerical Id of the group
- group_list: User list in the group, separated by comma.
The groups Command Tool
The groups command tells about the groups where the current user belongs to.
The output will be multiple group names the current user belongs to.
Changing Group With usermod Command
If you are group members you can be edit with usermod or useradd command.
When group is not listed then by default, usermod command will remove the user from every group of which he is a member.
Here : -a (append) option is used to prevent this from happening.
Sample syntax of :
# usermod -a -G <group> <userName>
Like example of
# usermod -a -G php Tom # usermod -a -G php abc # usermod -a -G java test2
See your terminal after run the command, we have displayed the list of /etc/group. User Tom and abc are add into the group php, user test2 is added into java.
Modifying Group Using groupmod Command
The groupmod command you can change the property of a group. It has multiple options:
- -n sets a new name for the group
- -p sets a new password for the group
To Change the name of the group, the syntax should be:
$ sudo groupmod -n <old-group-name> <new-group-name>
$ sudo groupmod -n students batch8
Deleting Groups Using groupdel Command
The groupdel will delete a group permanently from the system.
$ sudo groupdel <group-name>
$ groupdel students
Setting Group Password Using gpasswd Command
The gpasswd command tool can be user to set/update password for a group. However, this tool can also do many things like:
-aadd an user to a group
-dremove an user from a group
-rremove password from a group
-Aset the list of administrative users
The /etc/gshadow keeps the information about the group administrators. Each line of the file signifies: (from the left)
- group name: The general name of the group
- encrypted password: the encrypted password to enter the group for other users
- administrators: comma separated list of users who are the administrator of the group
- members: comma separated list of members of the group