欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

sudo chown "Operation not permitted" - how to resolve permissions to allow chown by admin or root users? 有大用 有大大用

可以看看  /node-admin/20451

sudo chown "Operation not permitted" - how to resolve permissions to allow chown by admin or root users?sudo chown“不允许操作” - 如何解析权限以允许管理员或 root 用户进行 chown?



As sanity check I was sudo chowning some folders due to having run some commands previously that generated some root owned files in my $HOME. I ended seeing an error in this process that got me curious:由于之前运行了一些命令,在我的 $HOME 中生成了一些 root 拥有的文件,因此我对一些文件夹进行了sudo chown检查。在这个过程中,我发现了一个错误,这引起了我的好奇:

chown: Library/Caches/com.mailplaneapp.Mailplane3/my@domain.tld/Downloads/151623a0c45f2b4_0.1.pdf: Operation not permitted

ls -l@ Library/Caches/com.mailplaneapp.Mailplane3/my@domain.tld/Downloads/151623a0c45f2b4_0.1.pdf doesn't reveal anything overly remarkable in this regard:ls -l@ Library/Caches/com.mailplaneapp.Mailplane3/my@domain.tld/Downloads/151623a0c45f2b4_0.1.pdf在这方面并没有发现什么特别之处:

-rw-r--r--@ 1 USERNAME  staff  335080 Aug 17  2018 Library/Caches/com.mailplaneapp.Mailplane3/my@domain.tld/Downloads/151623a0c45f2b4_0.1.pdf
    com.apple.metadata:kMDItemWhereFroms       284

I noticed this same thing from other files in this folder. Is there something I can do to strip whatever permissions might be preventing an admin / root user from modifying ownership via chown?我在该文件夹中的其他文件中也发现了同样的问题。我是否可以做些什么来取消可能阻止管理员/根用户通过 chown 修改所有权的权限?


Try either or both of these commands:请尝试执行其中一个或两个命令: 正确答案

sudo chflags noschg '/path/to/file.ext'

sudo chflags nouchg '/path/to/file.ext'


来自  https://apple.stackexchange.com/questions/381945/sudo-chown-operation-not-permitted-how-to-resolve-permissions-to-allow-chown




File can't be moved by root on OS XOS X 上的文件无法通过 root 移动I tried to move a few files to a subfolder on OS X. One refused to move. It said Operation not permitted. I tried again as root:

我尝试将一些文件移动到 OS X 上的子文件夹中。其中一个文件拒绝移动。它说Operation not permitted。我以 root 身份再次尝试:

$ sudo mv file subfolder/
mv: rename file to subfolder/file: Operation not permitted
$ sudo mv file filex
mv: rename file to filex: Operation not permitted
$ lsattr file
lsattr: Inappropriate ioctl for device While reading flags on file

I tried lsattr on other files; all files I tried gave me the same message: Inappropriate ioctl for device While reading...我在其他文件上尝试了 lsattr ;我尝试过的所有文件都给了我相同的消息:Inappropriate ioctl for device While reading...

Coming from Linux, I did not know about flags so here is the output of ls -leO@ file:来自 Linux,我不知道标志,所以这里是 ls -leO@ file 的输出:

$ ls -leO@ file otherfile
-rwxrwxrwx  1 eeytan  staff  uchg 79549 Nov 11  2010 file
-rw-r--r--  1 eeytan  staff  -     5071 Sep  7 02:37 otherfile

I tried the OS X Disk Utility; it said there were no errors on my disk. What's going on here?我尝试了 OS X 磁盘实用程序;它说我的磁盘上没有错误。这里发生了什么?


Sounds like the file is locked to me, which is why the uchg attribute is appearing. You should be able to use the following command to remove the locked attribute:

听起来该文件已被我锁定,这就是出现 uchg 属性的原因。您应该能够使用以下命令来删除锁定的属性:正确答案

chflags nouchg file

chflags -f -R nouchg directory on a higher level directory to stop this problem.在更高级别的目录上以阻止此问题。

or right-click the file in the Finder, click "Get Info" then uncheck the "Locked" checkbox或者在 Finder 中右键单击该文件,单击“获取信息”,然后取消选中“锁定”复选框


For people stumbling upon this in an OS X 10.11+ era (El Capitan or newer): Apple has added a whole new layer of security in OS X. They have taken away some privileges from root. The file you are trying to modify has a restricted flag. Only restricted processes which are signed by Apple will be able to modify these files. However, you can disable this security system by booting in recovery mode and disabling it in a Terminal by doing: csrutil disable.对于在 OS X 10.11+ 时代(El Capitan 或更高版本)中偶然发现这一点的人:Apple 在 OS X 中添加了全新的安全层。他们取消了 root 的一些权限。您尝试修改的文件有一个 restricted 标志。只有 Apple 签名的 restricted 进程才能修改这些文件。但是,您可以通过在恢复模式下启动并通过执行以下操作在终端中禁用它来禁用此安全系统:csrutil disable

Alternatively, you can also just start Terminal in Recovery Mode and delete the file there. Or even try booting in a Linux environment with HFS+ support (at least if you're not on APFS yet) to change the file.或者,您也可以在恢复模式下启动终端并删除其中的文件。或者甚至尝试在支持 HFS+ 的 Linux 环境中启动(至少如果您还没有使用 APFS)来更改文件。


我有一个无法在终端中删除的文件:

$ sudo ls -leO@ foo@example.com/Documents/.%cb_defense/cb.doc
-rw-rw-rw-  1 root  wheel  - 41984  1 Mar 11:20 foo@example.com/Documents/.%cb_defense/cb.doc

$ sudo rm -rf foo@example.com/Documents/.%cb_defense/cb.doc
rm: foo@example.com/Documents/.%cb_defense/cb.doc: Operation not permitted

What worked for me was opening Finder and deleting the containing directory whole. The way I understand it, Finder deletes directories as a unit entirely disregarding their contents, so it's not subject to the same restrictions as regular rm -rf.对我有用的是打开 Finder 并删除整个包含目录。据我了解,Finder 将目录作为一个整体删除,完全忽略其内容,因此它不受与常规 rm -rf 相同的限制。



I had this issue too, and I discovered that the folder the file was in was locked. So make sure that's not true. Do 'get info' on the folder in the finder, and make sure the locked checkbox is not checked.

我也遇到了这个问题,我发现文件所在的文件夹被锁定了。所以请确保这不是真的。在取景器中对文件夹进行“获取信息”,并确保未选中锁定的复选框。


在 OS 10.15 下,这对我有用:

  1. Recovery mode: command + R恢复方式:命令+R
  2. Utilities -> Terminal 实用程序 -> 终端 
  3. rm -r /path/to/file/or/dir/to/remove (The -r alone worked for me -- If you need it rm -rf force mode)rm -r /path/to/file/or/dir/to/remove ( -r 单独为我工作 - 如果你需要它 rm -rf 强制模式)
  4. Reboot 重启 



A previous answer said to use:之前的答案说使用:
chflags -f -R nouchg directory

There are two different attributes that prevent changing a file. "uchg" prevents the user from changing the file; "schg" prevents the system from making a change. Use ls -le0@ to see which is your problem, or use apple-I: if "locked" is checked but not greyed out, then "uchg" is set. If "locked" is checked AND greyed out, then "schg" is set.) If "uchg" is set, the previous answer will work. If "schg" is set, then do this instead:


有两种不同的属性可以防止更改文件。 “uchg”阻止用户更改文件; “schg”阻止系统进行更改。使用 ls -le0@ 查看您的问题,或使用 apple-I:如果选中“locked”但未灰显,则设置“uchg”。如果选中“locked”并且变灰,则设置“schg”。)如果设置“uchg”,则前面的答案将起作用。如果设置了“schg”,则执行以下操作:

chflags -f -R noschg directory


Before using arcane commands, confirm your System Preferences在使用神秘命令之前,请确认您的系统偏好设置

Terminal may not have permission to access your present working directory.终端可能无权访问您的present working directory

  1. Note your path (e.g. in Terminal, type 

    pwd

    ).记下您的路径(例如,在终端中,输入 pwd)。
  2. Visit  访问System Preferences > Security & Privacy > Privacy > Files and Folders 

    System Preferences > Security & Privacy > Privacy > Files and Folders

  3. Confirm there is a check mark next to any volumes and directories that appear in your path.确认路径中出现的所有卷和目录旁边都有复选标记

If Terminal has permissions and the command still gets an error, check the solutions provided in other answers.如果终端有权限但命令仍然出错,请检查其他答案中提供的解决方案。


0

I realize this is a very old topic but I don't see this thread addressing my symptom so I thought I'd post another opinion.我意识到这是一个非常古老的话题,但我没有看到这个帖子解决我的症状,所以我想我应该发表另一个意见。

I had this happen to an external drive that had been functioning perfectly on a Snow Leopard iMac, which got upgraded to El Capitan along the way. Earlier this year, I took that drive and put it in a new Windows 10 box which was running Paragon HFS for Windows. I copied hundreds of GB of files FROM Windows TO HFS+ on that drive and plugged it back into the iMac. Everything worked fine, except one shell script I had that staged files for backup encountered this uchg issue.我的一个外置硬盘曾在 Snow Leopard iMac 上完美运行,后来升级到了 El Capitan,就遇到了这种情况。今年早些时候,我将该驱动器放入一个运行 Paragon HFS for Windows 的新 Windows 10 盒子中。我将数百 GB 的文件从 Windows 复制到该驱动器上的 HFS+,然后将其插回 iMac。一切工作正常,除了我用于备份的暂存文件的一个 shell 脚本遇到了这个 uchg 问题。

In short: files and folders created under El Capitan or Windows 10 using Paragon HFS, when moved back to a Snow Leopard box, the "locked" radio box will NOT be checked when you select Get Info in the Finder. However, others' suggestions worked fine for me:简而言之:使用 Paragon HFS 在 El Capitan 或 Windows 10 下创建的文件和文件夹,当移回 Snow Leopard 框时,当您在 Finder 中选择 Get Info 时,不会选中“锁定”单选框。然而,其他人的建议对我来说效果很好:

  • verify that's the issue by running 

    ls -leO@

     (that's a capital oh) on a suspect file通过在可疑文件上运行 ls -leO@ (这是大写哦)来验证问题所在
  • as root, run 

    chflags -R nouchg

     on the parent directory (there's no -f in Snow Leopard)作为 root,在父目录上运行 chflags -R nouchg (Snow Leopard 中没有 -f)

It'll work, just don't expect the exact same visual cues if your drive has gone between operating systems or if you use Paragon HFS.它会起作用,只是如果您的驱动器在操作系统之间切换或使用 Paragon HFS,则不要指望完全相同的视觉提示。


来自  https://apple.stackexchange.com/questions/101328/file-cant-be-moved-by-root-on-os-x


普通分类: