简体   繁体   English

在Mac中仅通过root即可移动文件

[英]make a file removable just by root in mac

i'm trying to make a file removable just by root user In mac 10.10. 我试图使文件只能由root用户在Mac 10.10中移动。 i was try this : 我尝试了这个:

chown root <fileName>

but other user can remove it; 但其他用户可以删除它;

any idea? 任何想法?

As an alternative to changing the permissions on the containing directory, you can set the uimmutable flag on the file: 除了更改包含目录的权限之外,还可以在文件上设置uimmutable标志:

sudo chown root foo
sudo chflags uimmutable foo

Now only root will be able to delete foo. 现在只有root才能删除foo。 Note, though, that nobody will be able to modify the file, either. 但是请注意,任何人都无法修改文件。 Root could remove the uimmutable flag and then modify it, of course, but that opens a window for others to delete it. 根可以删除uimmutable标志,然后对其进行修改,但这会为其他人打开一个删除它的窗口。

The act of removing an entry in a directory modifies the directory, but not the file. 删除目录中的条目的操作会修改目录,但不会修改文件。 (When you remove a file, you are unlinking the name from the file and the link count on the file is decremented. The file itself may not be deleted, but will no longer be accessible by the name that was removed.) In order to ensure that only some process with root privilege can unlink a file, you need to modify the permissions on the directory. (当您删除文件时,您正在从文件中取消名称的链接,并且文件上的链接数将减少。该文件本身可能不会被删除,但是将无法通过被删除的名称进行访问。)确保只有具有root特权的某些进程才能取消链接文件,您需要修改目录的权限。 So to ensure that no-one but root can delete the file /p/a/t/h/file: 因此,为了确保除root之外没有人可以删除文件/ p / a / t / h / file:

sudo chown root /p/a/t/h  # make root the owner of the directory
sudo chmod og-w /p/a/t/h  # remove write permissions from other and group

Note that this is less fine grained that you might like and will prevent non-root users from removing or creating any files in /p/a/t/h . 请注意,您可能不喜欢这种细粒度的设置,它将阻止非root用户删除/p/a/t/h任何文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM