Sunday, May 5, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 581  / 2 Years ago, sat, april 30, 2022, 9:14:44

Uhy can you add a user to a group with usermod, but you cant remove a user from a group with usermod? Am I wrong?


I got a user I want to remove from the sudo group. I put this user in with usermod, now I have to use deluser to remove the user from the group?


On a test box, I ran sudo usermod -G "" user (bad advice form some thread I read) which removed all the groups, glad I didn't run that on the server.


From the man page, I see a -W option that mentions removing a list of gids. Are gids groups?


More From » command-line

 Answers
1

Although I wouldn't necessarily recommend it, you can in fact remove a user from a supplementary group with usermod - by passing a list of groups to keep to the -G command. From man usermod:



   -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
.
.
.

If the user is currently a member of a group which is not listed,
the user will be removed from the group. This behaviour can be
changed via the -a option, which appends the user to the current
supplementary group list.


Ex.


$ id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser),27(sudo),33(www-data),100(users)

$ sudo usermod -G users,www-data testuser

$ id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser),33(www-data),100(users)

[#240] Monday, May 2, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mentpengu

Total Points: 148
Total Questions: 114
Total Answers: 119

Location: Anguilla
Member since Sun, Aug 7, 2022
2 Years ago
mentpengu questions
Sun, Apr 17, 22, 18:09, 2 Years ago
Fri, Aug 12, 22, 01:35, 2 Years ago
Tue, Jul 26, 22, 14:52, 2 Years ago
Wed, Jun 30, 21, 02:28, 3 Years ago
;