0

I can use some advice on setting permissions on Linux.

I would like to grant a folder owner r-w access to files created by another user in the folder.

This is what I have so far.

The user silver is the owner of the folder. The user gold is in the silver group and can write to the /home/silver/tmp folder. How can I grant the user silver read-write access to the files user gold has created in the /home/silver/tmp folder.

Is there a way without adding silver to the gold group.

# getent group silver
silver:x:512:gold,silver

# ls -ld /home/silver/tmp
drwxrwxr-x 9 silver silver 4096 

#ls -l /home/silver/tmp
-rw-------  1 gold   gold  stats.txt

Thanks, Drew

2
  • Are you sure you got -rw------- 1 gold gold stats.txt (no silver in there) with ... | grep silver?
    – DonHolgo
    Aug 4, 2020 at 14:46
  • yes, that is incorrect. I edited the question.
    – Drew
    Aug 5, 2020 at 17:23

2 Answers 2

1

If you don't want to create a new group you can change the "umask" value of that particular user, in the "umask" keep the permission values of user and user group as it is, just change the value of others that is the last field. For example:

umask

enter the above command and let us assume the output is

0002

here ignore the first value(i.e '0') and in the remaining '002' first '0' is for the current user and the second '0' is for the group in which the user exists and '2' for remaining users. When ever you create a file with these 'umask' values it is created as

-rwxrwxr-x

that is first 'rwx' for the user, second 'rwx' for the group in which the user is present and the last 'r-x' is for others. Here in your case you want to give permission to the user outside the group you have to change this last value. See the output of the 'umask',let us assume it is 'abcd'. And here 'd' corresponds to the permissions to the users who are not in the group. To change this

umask abc1

i.e, don't change the values of 'abc' whatever they maybe just place '1' in place of 'd'.

1
  • I set chmod 2775 /home/silver/tmp to alter the setgid bit of the directory. this caused the files created in the directory to inherit the group from the parent folder. However the actual files are created with -rw------- 1 gold gold stats.txt. So I believe the only way to accomplish this is to apply your suggestion and alter the sticky bit of the file owner. This is something I will consider, as altering the sticky bit of the file owner impacts outside of this directory.
    – Drew
    Aug 5, 2020 at 19:33
0

You could create a new group, e.g., preciousmetal and add both gold and silver to it, then change the ownership of the folder to silver:preciousmetal, e.g:

chown -R silver:preciousmetal /home/silver/tmp
1
  • Thank you. I will try this. However the user silver is already the owner of the directory, but cannot read files created by gold in the directory.
    – Drew
    Aug 5, 2020 at 17:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .