How do I add users to another users group?

You can use: usermod -a -G grouptoadd username

Since it is far less obvious than I thought why -a -G is ok while -aG is not I'll try to explain it:

The -G options takes either one value or a list of values. In case of one value the value may be given like: -GVALUE since there is no requirement to have a space between the option and the value. This is just common practice.

If you have a group called a on your system, then calling -Ga becomes ambiguous. Do you want the user to have only one group a? Are you calling -a and -G? Then is "a" a value to -G? Where is the rest of the value (to -G)? It is also common practice that any single-letter option can before any other single letter option. so tat -xy == -yz. But this is ambiguous when one of the options can take either a single value like VALUE or many values like VAL1,Val2,val4,etc.

So in order to make the command FAILSAFE and work properly for all input you have to separate -a from -G

From man usermod:

Name

usermod - modify a user account

Synopsis

usermod [options] LOGIN

Description

The usermod command modifies the system account files to reflect the changes that are specified on the command line.

Options

The options which apply to the usermod command are:

  • -a, --append

    Add the user to the supplementary group(s). Use only with the -G option.

  • ...

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

    A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option.

    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.

  • ...