Chapter 7. Removing a user from a group using the command line
You can remove a user from a primary or supplementary group by overriding the groups the user belongs to with a new set of groups that does not contain the group you want to remove the user from.
7.1. Overriding the primary group of a user
This section describes how to use the usermod
utility to override the primary group of the user.
Prerequisites
-
Root
access
Procedure
To override the primary group of the user, use:
# usermod -g group-name username
Replace group-name with the name of the group, and replace username with the name of the user.
Example 7.1. Changing the primary group of a user
If the user
sarah
belongs to the primary groupssarah1
, and you want to change the primary group of the user tosarah2
, use:# usermod -g sarah2 sarah
Verification steps
To verify that the primary group of the user is overridden, use:
# groups sarah
The output returns:
sarah : sarah2
7.2. Overriding the supplementary groups a user
This section describes how to use the usermod
utility to override the supplementary groups of the user.
Prerequisites
-
Root
access
Procedure
To override the supplementary groups of the user, use:
# usermod -G group-name username
Replace group-name with the name of the group, and replace username with the name of the user.
Example 7.2. Changing the supplementary group of a user
If the user
sarah
belongs to thesystem-administrator
group and to thedeveloper
group and you want to remove the usersarah
from thesystem-administrator
group, you can do that by replacing the old list of groups with a new one. To do that, use:# usermod -G developer sarah
Verification steps
To verify that the supplementary groups of the user are overridden, use:
# groups sarah
The output returns:
sarah : sarah developer