Can a Linux user belong to more than one group?

Solution 1:

Yes, a user can be member of multiple groups:

Users are organized into groups, every users is in at least one group, and may be in other groups. Group membership gives you special access to files and directories which are permitted to that group.

For example, you can add the user username to groups group1 and group2 with the following usermod command:

usermod -a -G group1,group2 username

Solution 2:

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