Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 394
Serge Avatar asked Sep 15 '15 15:09

Serge


People also ask

How do you move to the root directory on a Mac?

anywhere on the Desktop, enter Command+Shift+G, then type / and hit return. This will take you to root (Macintosh HD)

Why can't I copy file to hard drive from Mac?

If you can't move or copy a file or folder, you might need to change its permissions settings. You might also need to change permissions settings for the disk, server, or folder where you want to move the item. On your Mac, select the item, then choose File > Get Info, or press Command-I.

Is Macintosh HD a root directory?

In Mac, the root directory can also be referred as Macintosh HD as this will show you the root directory files and folders. By default you won't find it in Finder and desktop as most of the users do not need to access the system files and folders.


2 Answers

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.

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

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

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.

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.

like image 190
Chris Ostmo Avatar answered Oct 19 '22 06:10

Chris Ostmo


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/)

like image 43
Haru Avatar answered Oct 19 '22 07:10

Haru