bash 在 OS X El Capitan 10.11 中复制 root 下的文件失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32590053/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:05:47  来源:igfitidea点击:

copying file under root got failed in OS X El Capitan 10.11

macosbashterminalosx-elcapitan

提问by Serhii

I'm trying to copy under root file into /System folder. It works well on all previous OS X version but not on El Capitan 10.11

我正在尝试将根文件下的复制到 /System 文件夹中。它适用于所有以前的 OS X 版本,但不适用于 El Capitan 10.11

Here how I copy file under root in terminal:

这是我如何在终端中复制 root 下的文件:

MACMINI:~ myusername$ sudo su -
MACMINI:~ root# cp /Users/myusername/Desktop/myfile.plist /System/Library/LaunchDaemons/

As result I receive an error:

结果我收到一个错误:

cp: /System/Library/LaunchDaemons/myfile.plist: Operation not permitted

采纳答案by Haru

Considering that certain system directories are protected from being written at all (even with root) under OS X 10.11 (El Capitan) unless security measurements are disabled (see answer by Chris Ostmo) it's obviously a good idea to not modify those directories at all with custom system hacks.

考虑到某些系统目录在 OS X 10.11 (El Capitan) 下完全不会被写入(即使是使用 root),除非禁用安全措施(请参阅Chris Ostmo 的回答),显然根本不修改这些目录是个好主意自定义系统黑客。

Own LaunchDaemons should be installed to:

自己的 LaunchDaemons 应该安装到:

/Library/LaunchDaemons/

(not /System/Library/LaunchDaemons/)

(不是/System/Library/LaunchDaemons/

回答by Chris Ostmo

El Capitan now protects certain system directories in "rootless" mode (a.k.a. System Integrity Protection). If you run the command ls -lO /System/Library/LaunchDaemonsyou'll see that the directories and files under there are now marked as "restricted."

El Capitan 现在以“无根”模式(又名系统完整性保护)保护某些系统目录。如果您运行该命令,ls -lO /System/Library/LaunchDaemons您将看到其下的目录和文件现在被标记为“受限”。

You can disable rootless mode like this:

您可以像这样禁用无根模式:

  1. Reboot into recovery mode (reboot and hold down Cmd-R)
  2. Open a terminal
  3. Use this command: csrutil disable
  4. Reboot and run the command that worked prior to El Capitan
  1. 重新启动进入恢复模式(重新启动并按住 Cmd-R)
  2. 打开终端
  3. 使用这个命令: csrutil disable
  4. 重新启动并运行在 El Capitan 之前运行的命令

When you're done, it is highly recommended that you re-enable SIP by following the same steps, but using csrutil enablein step 3.

完成后,强烈建议您按照相同的步骤重新启用 SIP,但csrutil enable在步骤 3 中使用。

I ran into a problem with the same root cause while trying to get pear/pecl modules and macports/homebrew apps installed. Those typically need to install files into /usr/include and /usr/lib, which are also now restricted.

我在尝试安装 pear/pecl 模块和 macports/homebrew 应用程序时遇到了相同根本原因的问题。那些通常需要将文件安装到 /usr/include 和 /usr/lib 中,现在它们也受到限制。

Note: Previous answers around the Internet about this problem give you instructions for modifying NVRAM settings, but Apple stated that the NVRAM method would stop working with El Capitan's public release. The GM release has already disabled the NVRAM workaround, so this answer should get you what you need moving forward.

注意:之前 Internet 上有关此问题的答案为您提供了修改 NVRAM 设置的说明,但 Apple 表示 NVRAM 方法将停止与 El Capitan 的公开版本一起使用。GM 版本已经禁用了 NVRAM 解决方法,因此这个答案应该可以满足您的需求。

UPDATE: This same method is applicable to macOS Sierra, and probably new macOS versions for the foreseeable future.

更新:同样的方法适用于 macOS Sierra,并且在可预见的未来可能适用于新的 macOS 版本。

ANOTHER UPDATE! It looks like Catalina's trying to do us in. They moved all the files I had previously forced to go where the Linux stuff had to go: Contents of /Users/Shared/Relocated Items

另一个更新!看起来 Catalina 试图让我们进去。他们把我之前被迫去 Linux 东西必须去的所有文件: /Users/Shared/Relocated Items 的内容

And they left this funny notice: What Are Relocated Items.pdfI'm kind of wondering whose computer I'm using now.

他们留下了这个有趣的通知: 什么是搬迁物品.pdf我有点想知道我现在在使用谁的电脑。

At any rate, I think most of the tools like brew and PEAR that used to need this workaround have adapted. I don't really know because making macOS behave 100% like Linux has become silly, so I use VMs when I need command line Linux things.

无论如何,我认为过去需要这种解决方法的大多数工具(如 brew 和 PEAR)已经适应。我真的不知道,因为让 macOS 100% 像 Linux 一样运行已经变得很愚蠢,所以当我需要命令行 Linux 东西时,我会使用 VM。

This workaround may still do the trick with Catalina. I haven't tried. I'm not going to do so for the sake of research, but I'll report back if I have a need to give it a shot.

此解决方法可能仍然适用于 Catalina。我没试过 我不会为了研究而这样做,但如果我需要试一试,我会回来报告。

回答by alan.waggett

No, but if you use 2nd copy of El Captainto boot your system, for example:

不,但如果您使用第二个El Captain副本来启动您的系统,例如:

Boot El Captain from a previous installation on a usb key, then you can do this

从 USB 密钥上的先前安装启动 El Captain,然后您可以执行此操作

cd /Volumes/Usb-Drive 

Then to show the directory in finder do this:

然后在finder中显示目录,请执行以下操作:

sudo chflags nohidden usr

Then just copy the files with your mouse, drag and drop into finder.

然后只需用鼠标复制文件,拖放到finder中。