RHEL 7.5 - How to remove user from a group?

18,739

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.

Share:
18,739

Related videos on Youtube

overexchange
Author by

overexchange

Updated on September 18, 2022

Comments

  • overexchange
    overexchange almost 2 years

    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?

    • Admin
      Admin over 5 years
    • Admin
      Admin over 5 years
      @Panther Reviewed and used all the options used in that query. no luck
    • Admin
      Admin over 5 years
      @Panther I tried usermod -G wheel appuser, it did not remove appuser from wheel