I think this question stems from a misunderstanding of how groups work. The groups listed in ls -l
are not the group that the user is potentially in, but the group that the file is owned by. Each file is owned by a user and a group. Often, this user is in the group, but this is not necessary. For example, my user is in the following groups:
$ groups
audio uucp sparhawk plugdev
but not in, say, the group cups
. Now, let's create a file.
$ touch foo
$ ls -l foo
-rw-r--r-- 1 sparhawk sparhawk 0 Feb 23 21:01 foo
This is owned by the user sparhawk
, and the primary group for me, which is also called sparhawk
. Let's now change the group owner of the file.
$ sudo chown sparhawk:cups foo
changed ownership of 'foo' from sparhawk:sparhawk to sparhawk:cups
$ ls -l foo
-rw-r--r-- 1 sparhawk cups 0 Feb 23 21:01 foo
You can see that the group that now owns the file is not a group that I am in.
This concept allows precise manipulation of file permissions. For example, you could create a group with members X, Y, and Z, and share files between the three of them. You could further give X write permissions, but only give the others (the group) read permissions.