groups command, although still useful, is mostly superseded by
the id command.)
A user has a primary group that is traditionally defined in the file
/etc/passwd file with which he logs in, but that today may have other sources.
He may also be a member of additional groups, known as secondary or
traditionally specified in the file
but which today can also come from or be implied by
additional sources (such as NIS, LDAP, SAMBA etc).
Primary and supplementary groups are defined at the time of login and remain current.
However, the user can at any time change his current active primary group
by using the
The login process sets the primary and supplementary groups.
For the later, it typically calls the libc function
which compiles the list of supplementary group data and passes it to the
which establishes it in the context of the process.
The sources of information for
used by the GNU C Library and certain other applications to
determine the sources from which to obtain name-service information
in a range of categories, and in what order. Each category of
information is identified by a database name.
groups command shows the groups as currently applied to your user,
and the list will start with the current primary group followed by the
supplementary groups from the time of login.
Any changes to the sources of the data from after the time of login
are not reflected in the displayed list.
groups username command is asking Linux to calculate the groups for that user,
which it will do using principally the files
/etc/groups and then the additional sources.
This will reflect the current situation of the system files and may not
equal the current groups that are still in effect from the time of login.
groups username command may give a different result
when it doesn't use all the sources that the login process used to calculate
your supplementary groups, which is what apparently happened in your case.
These sources may not be accessible from your login or may just not be consulted
by the command.
id username command may give better results, although also not guaranteed
to be as complete as that of the login process. The
is more recent than, and was intended to be more precise than,
groups command gives a precise and correct result,
you have well demonstrated that the
groups username command
cannot be depended upon to do the same.
Without examining the source-code of the
groups command, I would guess
that the implementation of the
groups username command in your Linux
/etc/groups, which in your case contained nothing,
but does not use
/etc/nsswitch.conf, from which came all of your
supplementary groups. Therefore is listed only the primary group name,
For more information see: