2

I am making multiple folders for users (userA/, userB/, etc.) where anyone can create/read a file/folder in any directory (userC can make fileX inside userA/). However, only the directory's owner can modify or delete the files within that folder (userC can only modify/delete files inside userC/).

I've tried changing the directory permissions to 7777, however the SUID doesn't apply to directories.

How do I allow uploaded files to inherit the directory owner?

Edit: UserZ owns directory dirZ/. UserZ can create (upload), modify, delete, and read everything inside dirZ/.
Likewise, UserY owns directory dirY/. User Y can create, modify, delete, and read everything inside dirY/.

UserY can access dirZ/. UserY can create or read anything inside dirZ/. UserY can not modify or delete anything inside dirZ/.

Likewise, UserZ can access dirY/. UserZ can create or read anything inside dirY/. UserZ can not modify or delete anything inside dirY/.

2 Answers 2

2

Most unix variants do not allow users to create files belonging to another user, for good reason.

It's rather strange that you would need that. If you want userC to be able to create and delete files inside userA/, give userC write permission to the directory. With your setup, the easiest way would be to put all these users in a common group mygroup and make all the user directories writable by that group.

chgrp mygroup userA userB userC
chmod g+w userA userB userC

Use access control lists (ACL) if you need more flexibility (e.g. multiple groups allowed to access these directories). See Make all new files in a directory accessible to a group if you need help activating ACLs on your system.

If you want users to be able to modify files in a directory other than theirs, either arrange for the files to be group-writable, or put a default ACL on the directory.

setfacl -d -m group:mygroup:rwx userA userB userC

If you really need to change the file's owner (but why does it matter since all the files are accessible to the same set of users anyway?), you can do it through a job that runs as root when a file is uploaded. On Linux you can use a tool based on inotify if you really need to, but it would be better to change the tool that performs the upload (for one thing, with an inotify-based solution, there is a small window of time where the file has the wrong ownership).

2
  • I don't want userC to be able to delete outside of userC/. I want users to be able to modify/delete files in their own folder. I don't want users to be able to modify/delete files in other users folders. Thanks for the answer, though.
    – BLaZuRE
    Apr 24, 2013 at 16:59
  • @BLaZuRE Your comment contradicts my understanding of your question. Please edit your question to clarify it. Which users should be able to write to which directories? Given your comment, why is it not sufficient to chown userA userA/ and so on? Apr 24, 2013 at 21:35
0

Unix file systems don't have windows-like access controls, which would enable you to make distinction between creating and modifying a file - once you give a user permission to create files in a directory (chmod +w) he/she is going to be able to modify them as well. Hence you need the server side to provide this extra functionality.

For example vsftpd can chown files for anonymous connections - I would expect it to be (more or less easily) extensible to other user accounts and chances are some other FTP daemons have this feature already.

If you don't necessarily have to use FTP, Samba seems to be able to do what you need - have a look at the (per share) inherit owner option.

You must log in to answer this question.

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