Yes, a regular unix user can be a member of multiple groups.
However, there's only one group of which is the user's primary group.
When adding a user, for example using adduser
, one can specify the primary group using the --ingroup
option, and add multiple secondary groups like this in Debian/Ubuntu and alike:
$ # would create user gert and group gert
$ sudo adduser gert
$ # same, but no group 'gert' will be created, but made member of the existing
$ # group 'adm'
$ sudo adduser gert --ingroup adm
$ # secondary groups
$ sudo adduser gert superusers
Adding user `gert' to group `superusers' ...
Adding user gert to group superusers
Done.
$ sudo adduser gert debianfans
Checking which user you're a member of can be done using id
:
$ id
uid=1000(gert) gid=1000(gert) groups=1000(gert),4(superusers),5(debianfans)
^^^ ^^^^^^
primary secondary
group groups
Also for other users, just by passing their username as a first argument to id
.
You can change the primary group of a user by using the -g
(--gid
) option usermod
$ usermod -g new_primary_group username