10

usermod does not have an option to remove user from a group

Usage: usermod [options] LOGIN

Options: -c, --comment COMMENT new value of the GECOS field -d, --home HOME_DIR new home directory for the user account -e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE -f, --inactive INACTIVE set password inactive after expiration to INACTIVE -g, --gid GROUP force use GROUP as new primary group -G, --groups GROUPS new list of supplementary GROUPS -a, --append append the user to the supplemental GROUPS mentioned by the -G option without removing him/her from other groups -h, --help display this help message and exit -l, --login NEW_LOGIN new value of the login name -L, --lock lock the user account -m, --move-home move contents of the home directory to the new location (use only with -d) -o, --non-unique allow using duplicate (non-unique) UID -p, --password PASSWORD use encrypted password for the new password -R, --root CHROOT_DIR directory to chroot into -s, --shell SHELL new login shell for the user account -u, --uid UID new UID for the user account -U, --unlock unlock the user account -Z, --selinux-user SEUSER new SELinux user mapping for the user account

Which command & options are used to remove a user from a group?

tshepang
  • 65,642
overexchange
  • 1,536

1 Answers1

14

The appropriate option is -G, but you don’t specify groups you want to remove, you specify groups you want to keep. If user is a member of group1 and group2, you can remove group2 by running

usermod -G group1 user

This will update user so that the only supplementary group membership is group1.

As mentioned in How do I remove a user from a group?, you can also use gpasswd:

gpasswd -d user group2

will remove user from group2.

Stephen Kitt
  • 434,908
  • and if a user is a member of 3 groups and you want to remove only 1 with usermod then the list of groups is coma-separated: usermod -G group1,group2 user – xealits Jul 05 '23 at 14:50