3

There is a directory I have

/var/new_share/KRA2017/Prateek

with these contents

-rwx------  1 superadmin   superadmin    0 Feb 16 15:14 file1.txt*
-rwx------  1 superadmin   superadmin    0 Feb 16 15:14 file2.txt*
-rwx------  1 superadmin   superadmin    0 Feb 16 15:15 file3.txt*
-rwx------  1 superadmin   superadmin    0 Feb 16 15:15 file4.txt*

in

/var/new_share/KRA2017/

The permission and ownership of directory /var/new_share/KRA2017/Prateek is

dr-xrwx--- 2 prateekkaien superadmin 4096 Feb 16 15:15 Prateek/

i.e the group owner can only write and user can only read and execute.

Whenever a file is being written by user superadminthe user and group owner of the files becomes superadmin as shown here. file1.txt file2.txt file3.txt file4.txt are written by user superadmin.

I want the user owner of the files to stick to prateekkaien with the same permissions r-x and the group owner to be superadmin with rwx permission like its parent directory.

How is this possible?

Basically all I want is for the files to inherit the owner, group, and permissions of the parent directory.

5
  • 5
    You can force the group ownership with the setgid bit on directories, but it works only for the group, not for the user. So the question becomes: why do you want to change user ownership, too, and what do you hope to achieve by that?
    – dirkt
    Feb 16, 2017 at 10:08
  • I want the user to be able to read/view the file. When a file is being created it is being user-owned by 'superadmin' with permission rwx Basically all I want is, the files to inherit the same user and groups and same permissions and ownerships as of the parent directory Feb 16, 2017 at 10:17
  • 2
    You could swap user and group to achieve this: Create a group prateekkaien (or use an existing one), use setgid as described by @dirkt, set the permissions accordingly and leave the user untouched.
    – Murphy
    Feb 16, 2017 at 10:21
  • As a further example, you normally just make groups according to the necessary roles, and then assign users to it. For example, my /usr/local as a setgid of staff, and I'm member of staff, so I can work with files below /usr/local any way I want. If some other user who is also a member of staff does the same, I don't care, because as a member of the same group, I can modify his files etc.
    – dirkt
    Feb 16, 2017 at 10:27
  • By this, will not the user 'prateekkaien' gain access of rwx as of the group ? The superuser is the administrator. It can create and modify files but the user can only view/read it. I didnt get what it says above Feb 16, 2017 at 10:36

2 Answers 2

1

You are trying to enforce r-x access to owner user prateekkaien, and rwx access to owner group superadmin. This won't work because prateekkaien, as file owner, has full permission over it and it can simply do a chmod u+r to gain write access to the file.

What you could do is set the SGID bit on the directory, as @dirkt and @Murphy commented, so all newly created files will have superadmin as owner group.

0

On Unix the owner of a file is the user, who created it.

There are several questions, which already answer this and explain why:

1
  • I found a funny case. System without entry for the user in /etc/passwd. When the user creates file or directory the owner is root.
    – gaoithe
    Nov 24, 2022 at 18:46

You must log in to answer this question.

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