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

你。 提交于 2019-12-03 03:49:26

问题


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

Here how I copy file under root in terminal:

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

回答1:


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.

Own LaunchDaemons should be installed to:

/Library/LaunchDaemons/

(not /System/Library/LaunchDaemons/)




回答2:


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/LaunchDaemons you'll see that the directories and files under there are now marked as "restricted."

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

When you're done, it is highly recommended that you re-enable SIP by following the same steps, but using csrutil enable in step 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.

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.

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




回答3:


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

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

cd /Volumes/Usb-Drive 

Then to show the directory in finder do this:

sudo chflags nohidden usr

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



来源:https://stackoverflow.com/questions/32590053/copying-file-under-root-got-failed-in-os-x-el-capitan-10-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!