目录中创建的所有文件应归 bob 所有

目录中创建的所有文件应归 bob 所有

我正在寻找 bob 拥有的目录中的所有文件。我知道我可以 chmod g+s 来获取新文件上设置的组,但我不认为我可以为用户做类似的事情。

这就是我想出的..或者还有其他方法可以做到这一点吗?

[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 ~]# 

谢谢

答案1

通常不可能使目录中的文件由特定用户拥有(除非该用户首先写入文件)。原因是(在大多数 Unix 变体下,包括 Linux)禁止泄露文件

但是,您可以通过使用提供不同文件所有权的文件系统来实现此效果。这里的一种可能性是绑定文件系统,它呈现了不同位置的文件系统的视图,可能会修改所有权和权限。如果您bindfs以非 root 用户身份运行且没有该--no-allow-other选项(需要user_allow_otherin /etc/fuse.conf),则在 bindfs 视图中创建的文件将由提供 bindfs 文件系统的用户拥有。

如果您需要的是 Bob 有权访问文件,而不是 Bob 拥有文件的所有权,那么按照您在问题中描述的方式使用 ACL 是最好的方法。

相关内容