valker
valker

Reputation: 143

How to change user affilations to group in Linux

I have several users say: A,B,C,D, etc. and 2 group: master, slave. Each user belongs to only one of these groups (exclusively). How can I programmatically change this belonging?

For example: user A belongs to group "master" How to remove it from group "master" and add it to group "slave"?

Upvotes: 1

Views: 231

Answers (1)

Šimon Tóth
Šimon Tóth

Reputation: 36451

From the man page of usermod:

-G, --groups group,...
With this option a list of supplementary groups can be specified, which the user should become a member of. Each group is separated from the next one only by a comma, without whitespace. The user is removed from all other groups not specified.


-R, --remove-from-group group,...
With this option a list of groups can be specified, from which the user should be removed. Each group is separated from the next one only by a comma, without whitespace.

If for some reason this isn't pre-installed on your system it is a command from the pwdutils package.

Upvotes: 1

Related Questions