Ubuntu – Relationship between file/folder’s owner and group

groupspermissionsusers

I found that a directory with following ls output in my system:

drwxr-xr-x   5 username   root  4096 Jan 14  2015 DIRNAME

It rose a question for me: Is there any restriction between files owner and group? I mean that each user in the system belongs to predefined group(s). Is it possible to assign a "group" to a file/folder that the file user (owner) does not belong to?

Best Answer

Is it possible to assign a "group" to a file/folder that the file user (owner) does not belong to?

Certainly. For example:

$ sudo ls -l /var/spool/cron/crontabs
total 8
-rw------- 1 muru     crontab 1136 Jul 21 12:30 muru
-rw------- 1 root     crontab 1090 Jan 20  2015 root

$ groups
muru adm cdrom sudo dip plugdev lpadmin sambashare
$ groups root
root : root

As you can see, neither root, nor muru, are members of crontab, yet the crontab files' group owner is crontab.

Is there any restriction between file's owner and group?

None at all1.


1Well, there are restrictions on each individually: the UIDs and GIDs have to be 32-bit integers (IIRC), or the username and group names must exist:

# touch /tmp/foo
# chown 1000000000:2000000000 /tmp/foo
# ls -l !$
ls -l /tmp/foo
-rw-r--r-- 1 1000000000 2000000000 0 Sep 15 09:04 /tmp/foo
# chown gibberish:garbage /tmp/foo
chown: invalid user: ‘gibberish:garbage’

But, no, no relation between owner and group.

Related Question