2

I'm looking to have all files in a directory owned by bob. I'm aware I can chmod g+s to get the group set on new files but I don't think I can do anything like that for the user.

This is what I've come up with.. or is there another way to do this ?

[root@testmachine ~]# mkdir /testing.d
[root@testmachine ~]# setfacl -m default:u:bob:rwx,default:g:testgroup:rwx /testing.d/
[root@testmachine ~]# touch /testing.d/someone
[root@testmachine ~]# getfacl /testing.d/someone 
getfacl: Removing leading '/' from absolute path names
# file: testing.d/someone
# owner: root
# group: root
user::rw-
user:bob:rwx            #effective:rw-
group::r-x          #effective:r--
group:testgroup:rwx     #effective:rw-
mask::rw-
other::r--

[root@testmachine ~]# getfacl /testing.d/
getfacl: Removing leading '/' from absolute path names
# file: testing.d/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx
default:user:bob:rwx
default:group::r-x
default:group:testgroup:rwx
default:mask::rwx
default:other::r-x
[root@testmachine ~]# 

Thanks

  • http://superuser.com/questions/471844/why-is-setuid-ignored-on-directories – Rui F Ribeiro Feb 11 '16 at 02:55
  • chmod u+s your_directory This command will force the ownership of new subdirectories and files to be the owner of the containing directory – AReddy Feb 11 '16 at 05:28

1 Answers1

1

It is normally impossible to cause files in a directory to be owned by a particular user (unless that user was writing the files in the first place). The reason is that (under most Unix variants, including Linux) it's forbidden to give away files.

However you can achieve this effect by using a filesystem that presents a different ownership of files. One possibility here is bindfs, which presents a view of a filesystem at a different location, possibly with modifies ownership and permissions. If you run bindfs as a non-root user without the --no-allow-other option (which requires having user_allow_other in /etc/fuse.conf) then files created in the bindfs view will be owned by the user providing the bindfs filesystem.

If what you need is that Bob has access to the files, not that Bob has ownership of the files, then using ACL the way you describe in your question is the best way.