automaticaly assign ownership of folder to new file: how ??

Jon LaBadie ubu at labadie.us
Sat Nov 5 06:46:46 UTC 2022


On Fri, Nov 04, 2022 at 10:08:54AM +0000, Chris Green wrote:
>On Fri, Nov 04, 2022 at 09:38:30AM +0100, robert rottermann wrote:
>> Hi there
>>
>> i am using Ubuntu 20.04.
>>
>> Is there a way, that when creating a file in a folder, that it automatically
>> inherits the ownership of the folder.
>> And not the one of the user creating the file?
>>
>It's quite well buried in the documentation but if you set the
>'sticky' bit (I think it's that one) in the permissions of a directory
>then you get what you want.

Terminology correction, it is the "Set group id" bit.

>
>Yes, I've just tried it:-
>
>    chris$ mkdir test
>    chris$ sudo -s
>    [sudo] password for chris:
>    root at t470# ls -al test
>    total 8
>    drwxrwxr-x  2 chris chris 4096 Nov  4 10:05 .
>    drwxr-xr-x 21 chris chris 4096 Nov  4 10:05 ..
>    root at t470# chmod 2755 test

Correct command for sgid bit.  The sTicky bit would
be set with "chmod 1755 test".
                    ^
>    root at t470# ls -la test
>    total 8
>    drwxr-sr-x  2 chris chris 4096 Nov  4 10:05 .
>    drwxr-sr-x  2 chris chris 4096 Nov  4 10:05 .

IF the sTicky bit were set instead of sgid bit you would see:
      drwxr-xr-t  2 chris chris 4096 Nov  4 10:05 .


>    drwxr-xr-x 21 chris chris 4096 Nov  4 10:05 ..
>    root at t470# chgrp isbd test
>    root at t470# ls -al test
>    total 8
>    drwxr-sr-x  2 chris isbd  4096 Nov  4 10:05 .
>    drwxr-xr-x 21 chris chris 4096 Nov  4 10:05 ..
>    root at t470# exit
>    exit
>    chris$ cd test
>    /home/chris/tmp/test
>    chris$ ls -al
>    total 8
>    drwxr-sr-x  2 chris isbd  4096 Nov  4 10:05 .
>    drwxr-xr-x 21 chris chris 4096 Nov  4 10:05 ..
>    chris$ touch fred
>    chris$ ls -al
>    total 8
>    drwxr-sr-x  2 chris isbd  4096 Nov  4 10:06 .
>    drwxr-xr-x 21 chris chris 4096 Nov  4 10:05 ..
>    -rw-rw-r--  1 chris isbd     0 Nov  4 10:06 fred
>    chris$
>
>

-- 
Jon H. LaBadie                  ubu at labadie.us



More information about the ubuntu-users mailing list