According to pw usermod documentation:

-G grouplist Set secondary group memberships for an account. grouplist is a comma, space, or tab-separated list of group names or group numbers. The user is added to the groups specified in grouplist, and removed from all groups not specified. The current login session is not affected by group member- ship changes, which only take effect when the user recon- nects. Note: do not add a user to their primary group with grouplist.

I tried

pw usermod test_user -G ''

but that command has no effect at all.

Workaround: Delete a user from all groups except one:

pw usermod test_user -G test_group

and then delete user from that group:

pw groupmod test_group -d test_user

But this requires creating a trash group or knowing one of users groups. Is there a simpler way?

1 Answer 1


Sadly, there doesn't seem an easy way. However, it is trivial to get a comma separated list of secondary groups for a user:

pw usershow $user -P | grep Groups: | cut -w -f 3  

You can iterate over that easily enough and use:

pw groupmod $group -d $user

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .