On Linux®, providing you 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. You 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-name
where
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-name
where 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-name
where
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 you 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-name
where
user-name is the user name.