How to make files created in a directory owned by directory group?

20,353

Solution 1

If you chmod g+s directory then all the files created in that directory will be owned by that group.

newgroup is really a holdover from the days when you could only be in one group, and isn't really needed nowadays.

Solution 2

Files created by user are created with his current group ID. To check user ids you can execute id; to change your GID to something from the list of your groups use newgrp <group> or sg <group> <command>: first command will launch shell and the latter will just run a command with GID set to <group> id.

Check this shell 'log':

whitequark@forth:~/test$ id
uid=1000(whitequark) gid=1000(whitequark) groups=4(adm),20(dialout),24(cdrom),
46(plugdev),104(lpadmin),114(admin),118(sambashare),1000(whitequark)
whitequark@forth:~/test$ touch file1
whitequark@forth:~/test$ ls -la
total 8
drwxr-xr-x  2 whitequark whitequark 4096 2010-01-29 19:49 .
drwxr-xr-x 82 whitequark whitequark 4096 2010-01-29 18:02 ..
-rw-r--r--  1 whitequark whitequark    0 2010-01-29 19:49 file1
whitequark@forth:~/test$ newgrp admin
<<< at this point a new shell is started >>>
whitequark@forth:~/test$ touch file2
whitequark@forth:~/test$ ls -la
total 8
drwxr-xr-x  2 whitequark whitequark 4096 2010-01-29 19:49 .
drwxr-xr-x 82 whitequark whitequark 4096 2010-01-29 18:02 ..
-rw-r--r--  1 whitequark whitequark    0 2010-01-29 19:49 file1
-rw-r--r--  1 whitequark admin         0 2010-01-29 19:49 file2
Share:
20,353
singpolyma
Author by

singpolyma

Filling out this field.

Updated on September 17, 2022

Comments

  • singpolyma
    singpolyma over 1 year

    Is there a way, on Linux, to cause all new files created in a directory to be owned by the directory's group instead of the creating user's group?