After I look through the help. I didn't found much difference between them.

-g, --gid GROUP

The group name or number of the user's initial login group. The group name must exist. A group number must refer to an already existing group.

-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. The default is for the user to belong only to the initial group.

If they are the same. Why both they exist?


-g sets the initial, or primary, group. This is what appears in the group field in /etc/passwd. On many distributions the primary group name is the same as the user name.

-G sets the supplementary, or additional, groups. These are the groups in /etc/group that list your user account. This might include groups such as sudo, staff, etc.

  • Thank you kind and quick help . @roaima Did you mean the primary group (-g) and secondary group(-G)? Thanks. – Joe.wang Jun 29 '16 at 11:33
  • @Joe.wang yes. "Supplementary", "secondary", and "additional" are names for the same thing. Kusalananda's answer shows this quite clearly with the id command, I think. – roaima Jun 29 '16 at 11:44

They are not the same. The -g option specifies the "primary" group that a user should belong to, while the -G option specifies one or many supplementary ("secondary") groups.

On a work machine I have access to I have

$ id
uid=1001(me) gid=1001(me) groups=1001(me),27(sudo),110(lxd),1005(theproject)

This shows that my "primary" group is me (same as my username). However, I'm also member of a number of secondary groups.

Membership of the sudo group, for example, allows me to use the sudo command to do scary stuff with the system, due to the way this is configured for sudo in /etc/sudoers on this particular machine.

Membership of the theproject group allows me to modify group-readable/writable files in a project I'm working on with others.

File created will (ordinarily) automatically be assigned to the primary group.


The group applied via -g is the primary group, so for example when you create a file it will default to making it with your primary group as the group associated with that file. You can however temporarily change which group it uses as default with the sg or newgrp commands. All groups in the -G are secondary groups. More about this here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.