在Linux中的目录下为新创建的文件和子目录设置默认权限? [英] Setting default permissions for newly created files and sub-directories under a directory in Linux?

查看:1028
本文介绍了在Linux中的目录下为新创建的文件和子目录设置默认权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆长时间运行的脚本和应用程序,它们将输出结果存储在几个用户之间共享的目录中.我想要一种方法来确保在此共享目录下创建的每个文件和目录都自动具有u=rwxg=rwxo=r权限.

I have a bunch of long-running scripts and applications that are storing output results in a directory shared amongst a few users. I would like a way to make sure that every file and directory created under this shared directory automatically had u=rwxg=rwxo=r permissions.

我知道我可以在各种脚本的开头使用umask 006,但是我不喜欢这种方法,因为许多用户编写自己的脚本,可能会忘记自己设置umask.

I know that I could use umask 006 at the head off my various scripts, but I don't like that approach as many users write their own scripts and may forget to set the umask themselves.

我真的只希望文件系统在某个文件夹中时,以一定的权限设置新创建的文件和目录.这是可能吗?

I really just want the filesystem to set newly created files and directories with a certain permission if it is in a certain folder. Is this at all possible?

更新:我认为可以通过 POSIX ACL (使用默认ACL功能),但此刻我有点头疼.如果有人可以解释如何使用默认ACL,则可能会很好地回答这个问题.

Update: I think it can be done with POSIX ACLs, using the Default ACL functionality, but it's all a bit over my head at the moment. If anybody can explain how to use Default ACLs it would probably answer this question nicely.

推荐答案

要获得正确的所有权,可以使用

To get the right ownership, you can set the group setuid bit on the directory with

chmod g+rwxs dirname

这将确保在目录中创建的文件归该组所有.然后,您应该确保每个人都使用umask 002或007或类似的特性运行-这就是为什么Debian和许多其他Linux系统默认配置有按用户组.

This will ensure that files created in the directory are owned by the group. You should then make sure everyone runs with umask 002 or 007 or something of that nature---this is why Debian and many other linux systems are configured with per-user groups by default.

如果用户的umask太强,我不知道一种强制您想要的权限的方法.

I don't know of a way to force the permissions you want if the user's umask is too strong.

这篇关于在Linux中的目录下为新创建的文件和子目录设置默认权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆