自动为文件夹中的新创建文件授予权限
我有一个权限设置为777的文件夹,但是当我在该文件夹中添加任何文件或文件夹解压缩时。 提取的文件或文件夹权限永远不会更改。 目标文件夹权限是777,我想要在该文件夹中添加的内容将自动获得777的许可。
当我通过在该文件夹中解压缩.zip来添加任何文件或文件夹时,提取的文件夹/文件权限不会自动更改。 我总是要chmod新添加文件/文件夹!
您想要的是ACL – 访问控制列表 。
访问控制列表(ACL)为文件系统提供了更多,更灵活的权限机制。 它旨在帮助UNIX文件权限。 ACL允许您将任何用户或组的权限授予任何光盘资源。
应该已经安装了acl
包,检查它运行: dpkg -s acl
。
要使用ACL,您应该为您的文件系统启用它。 但它已经可以启用了 。 要检查它,请使用tune2fs -l
。 替换/dev/sda6
为您的系统:
$ tune2fs -l /dev/sda6 | grep "Default mount options:" Default mount options: user_xattr acl
如果你看到acl word – 它已经为设备/dev/sda6
启用了。
如果你没有看到acl word – 运行tune2fs -o acl /dev/sda6
来启用它。
要修改ACL,请使用setfacl命令。 要添加权限,请使用setfacl -m 。
要为用户设置权限:
$ setfacl -m "u:username:rwx" /path/to/folder
这将设置rwx
ACL,用户username
/ path / to / folder。 这意味着在此文件夹中创建的所有文件都具有username
rwx
权限。
要为组设置权限:
$ setfacl -m "g:groupname:rwx" /path/to/folder
这将设置rwx
ACL,组groupname
为/ path / to / folder。 这意味着在此文件夹中创建的所有文件都具有组groupname
rwx
权限。
为其他人设置权限:
$ setfacl -m "o:rwx" /path/to/folder
这将设置rwx
ACL,其他为/ path / to /文件夹。 这意味着在此文件夹中创建的所有文件都具有rwx
权限。
要检查权限:
$ getfacl /path/to/folder
结合acl
$ setfacl -mu:username:rwx,g:groupname:rwx,o:rwx /path/to/folder
默认ACL
The new object inherits the default ACL of the containing directory as its access ACL. If no default ACL is associated with a directory, the mode parameter to the func‐ tions creating file objects and the file creation mask (see umask(2)) are used to determine the ACL of the new object: The new object is assigned an access ACL containing entries of tag types ACL_USER_OBJ, ACL_GROUP_OBJ, and ACL_OTHER. The permissions of these entries are set to the permissions specified by the file creation mask.
因此,如果您设置默认ACL,则它将是首选 ACL。 这意味着如果为user
或group
设置ACL,新创建的文件将inheritance默认的 acl。 小心使用默认ACL。
要设置默认acl,请使用-d
键,
$ setfacl -d -mu::rwx,g::rwx,o::rwx /path/to/folder
或使用default
字
$ setfacl -m default:u::rwx,default:g::rwx,default:o::rwx /path/to/folder
小心设置默认ACL。 例如,如果设置如下:
$ setfacl -d -mo:--x /path/to/folder
现在获取此ACL
$ getfacl /path/to/folder # file: path/to/folder # owner: c0rp # group: c0rp user::rwx group::rwx other::--x default:user::rwx default:group::rwx default:other::--x
组和用户的默认ACL将自动为rwx
!
删除ACL
$ setfacl -b /path/to/folder
这将从文件夹中删除所有ACL
最后
如果您只是系统用户,我建议使用默认ACL。
$ setfacl -d -mu::rwx,g::rwx,o::rwx /path/to/folder
这将为/ path / to / folder做你想要的
来源
archlinux – https://wiki.archlinux.org/index.php/Access_Control_Lists
help.ubuntu – https://help.ubuntu.com/community/FilePermissionsACLs