如何保护可写目录下的文件

问题描述 投票:0回答:1

我遇到文件许可权和ACL问题。我有一个权限为777(dir rwxrwxrwx)的可写目录名称“ dir”在目录下,我创建一个文件tmp.txt(dir / tmp.txt)

我想知道如何在不更改“ dir”权限的情况下停止其他/组成员编辑/删除文件。每个人都可以自由地对“目录”下的其他文件/目录执行任何操作。

我想知道也许是“ setfacl”还是什么。

linux file unix permissions acl
1个回答
0
投票
有两种方法可以带您到达想要的地方。

想法1-粘性位

$ ls -ld /tmp drwxrwxrwt 33 root root 1020 2020-03-14 14:06 /tmp/

这是Unix /tmp目录的通用权限。权限末尾的t表示sticky bit,您可以通过运行以下命令进行设置:
chmod +t /tmp

粘性表示即使每个人都对该目录具有写许可权,唯一可以删除该目录下文件的人是root,目录所有者和文件所有者。

想法2-额外目录​​

如果目录不为空,则无法删除。如果将文件放在您拥有的目录中,只有您(和root)可以删除文件,其他任何人都不能删除它:

root@playground# tree -up . `-- [drwxrwxrwx root ] box |-- [-rw-r--r-- test1 ] f1 `-- [drwxr-xr-x test2 ] hello `-- [-rw-r--r-- test2 ] f2 2 directories, 2 files root@playground# su test1 test1@playground$ rm box/hello rm: cannot remove ‘box/hello’: Is a directory test1@playground$ rm -rf box/hello/ rm: cannot remove ‘box/hello/f2’: Permission denied

© www.soinside.com 2019 - 2024. All rights reserved.