Removing User from Secondary Group in Linux
Abstract: Change USER with your actual user name and GROUP with named of group from which you want to delete user. Example Use the following command to remove u
All the groups except the primary group are called the secondary groups of Users, for whom they belong. Generally, the primary group is created at the time of user-created with the same name. You can also assign a user to other groups to inherit their group permissions.
SyntaxThe gpasswd
command uses the following syntax for removing a user from group.
gpasswd --delete USER GROUP
Change USER with your actual user name and GROUP with named of group from which you want to delete user.
ExampleUse the following command to remove user jack from sudo group.
gpasswd -d jack sudo
Instead of -d
, you can also use its long version --delete
.
Once you deleted a user from the group, check the list of groups the user belongs to.
cat /etc/group | grep jack
Add User to a Secondary Group
In case you realize that you didn’t want to remove that user from the group. Also, you may be required to add another user to that group. Use the following command to add a user to a second group.
usermod -aG sudo jack
The above command will add user 「jack」 to the group named 「sudo」.
ConclusionHope this FAQ contains the useful information you required.