Creating user group is fundamental to the process of user management in Linux. Most Unix systems come with many user groups built in, most of them system groups out of the box, that is usually sufficient for single user systems. If you have multiple users on the same system, then you probably want to create your own groups to manage the users better.
The command to create a new user group is groupadd. The groupadd command creates the user group based on the default values configured on the system as well as the values specified on the command line.
The biggest advantage of creating different groups is the ease in permissioning – creating different security levels for different set of users. Obviously you created the user groups so that you can add users to it. After you have created the user group, you will be able to assign users to the new created group.
There are some options can be specific with the groupadd command. Some of the most commonly used are:
- -g GID : specify a group id that you want to use for this group. The GID should be a non-negative numerical value that is unique across all user groups. By default the group id is the smallest available numerical value above 500 but is higher than every other existing user groups in the system.
- -r : This will create the group as a system group.
Most times you will only need to create a user group with the default configuration. In order to create a user group with the name, says cats
This will create a new user group called cats with the default options.
In order to create a group called cats with the group id 999, you can use the command
groupadd -g 999 cats
After you have created the user groups that you need, you might want to verify that the creation was successful with the options that you specified. The system keeps the group information in various system files. The group information is in the file /etc/group. The file /etc/gshadow keeps the secure group account information.
cat /etc/group | grep cats
Group names can only be a maximum of 32 characters long. Also, the group id should be unique across all user groups, unless you have configured the system specifically to have non-unique group ids.
You can add users to the newly created user groups in order to manage them better and to assign specific permissions to each of the groups.
Another command called addgroup is also available in many systems. This is a usually an interactive wrapper around the groupadd command, and may or may not be available depending on the Linux distribution you have.