bash 如何将目录设置为具有持久组权限?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/528920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you set a directory to have persistent group permissions?
提问by Nick Sergeant
We have two users:
我们有两个用户:
- user1
- user2
- 用户 1
- 用户 2
They both belong to the group 'admin'.
他们都属于“admin”组。
We have a directory that has been set to 775. The directory's group has been changed to 'admin'. Each user has full access to write into that directory, though when a user writes a new file to the directory, the group permissions of the folder are not persisted to the file that was written.
我们有一个已设置为 775 的目录。该目录的组已更改为“admin”。每个用户都具有写入该目录的完全访问权限,但当用户将新文件写入该目录时,该文件夹的组权限不会保留到写入的文件中。
How should we make it so that files inherit the directory's group permissions?
我们应该如何使文件继承目录的组权限?
Clarification: when a new file or directory is written, it uses the users' group as the group of the new file, rather than that of the directory, which makes sense - but how do I not make that happen?
澄清:写入新文件或目录时,它使用用户组作为新文件的组,而不是目录的组,这是有道理的 - 但我怎么不这样做呢?
采纳答案by Nietzche-jou
You can propagate group permissions by setting the directory's setgid bit (chmod g+s). This may not be portable across all *nixes and all file systems.
您可以通过设置目录的 setgid 位 ( chmod g+s)来传播组权限。这可能无法跨所有 *nix 和所有文件系统移植。
http://en.wikipedia.org/wiki/Setuid#setgid_on_directories
http://en.wikipedia.org/wiki/Setuid#setgid_on_directories
http://www.gnu.org/software/coreutils/manual/html_node/Directory-Setuid-and-Setgid.html
http://www.gnu.org/software/coreutils/manual/html_node/Directory-Setuid-and-Setgid.html
回答by Mike
If you are using ext3 or ReiserFS, this page about creating a Linux file servermay help. Specifically step 7 suggests the following command.
如果您使用的是 ext3 或 ReiserFS,这个关于创建 Linux 文件服务器的页面可能会有所帮助。具体步骤 7 建议使用以下命令。
setfacl -d -m g:sales:rw /groups/sales
回答by samoz
I think you should look here.
我想你应该看看这里。
As the site says, "Unix doesn't support the idea of inherited permissions."
正如该站点所说,“Unix 不支持继承权限的想法。”
However, there is a section on ACLs (Access Control Lists), which I think is what you are looking for. By setting up an ACL, you can have your files inherit the same ACL from the directory, which I think is what you are asking for. setfacl is the shell command that will be what you need to look into.
但是,有一个关于 ACL(访问控制列表)的部分,我认为这正是您要查找的内容。通过设置 ACL,您可以让您的文件从目录中继承相同的 ACL,我认为这正是您所要求的。setfacl 是您需要查看的 shell 命令。
Hope that helps!
希望有帮助!

