Create and manage groups on Linux
On Linux, providing we are not using NIS or NIS+, use the /etc/group file to work with groups.
About this task
On Linux, group information is held in the /etc/group file. We can use commands to create a group, add a user to a group, display a list of the users who are in the group, and remove a user from a group.
Procedure
- To create a new group, use the groupadd command. Type the following command:
groupadd -g group-ID group-namewhere group-ID is the numeric identifier of the group, and group-name is the name of the group.- To add a member to a supplementary group, use the usermod command to list the supplementary groups that the user is currently a member of, and the supplementary groups that the user is to become a member of. For example, if the user is already a member of the group groupa, and is to become a member of groupb, use the following command:
usermod -G groupa,groupb user-namewhere user-name is the user name.- To display who is a member of a group, use the getent command. Type the following command:
getent group group-namewhere group-name is the name of the group.- To remove a member from a supplementary group, use the usermod command to list the supplementary groups that we want the user to remain a member of. For example, if the user's primary group is users and the user is also a member of the groups mqm, groupa and groupb, to remove the user from the mqm group, use the following command:
usermod -G groupa,groupb user-namewhere user-name is the user name.Parent topic: Set up security on UNIX, Linux, and Windows