10

Environment: OSX Sierra, Darwin Kernel Version 16.3.0

Root Problem: I want to use a bunch of shell scripts in a central repository, which have a #!/usr/bin/zsh. On my Mac, the zsh is in /bin/zsh.

Attempted solution: I want to create a symbolic link

ln -s /bin/zsh /usr/bin/zsh

My user account has admin rights, but I am not root, and I would prefer not to enable the root user on this Mac. Therefore I first did a

sudo su

to get a shell with root privileges and then executed the ln command. However I still get the error message ln: /usr/bin/zsh: Operation not permitted.

Questions:

  • Why do I get this error message?

  • What would have I to do to create the link?

  • Is there a better way to achieve my original goal? Note that fixing the #! lines is not an option.

  • Why don't you just copy /usr/bin/zsh to /bin/zsh? – Lenniey Jan 18 '17 at 12:31
  • 1
    @Lenniey That way you're creating a loose copy that won't be updated together with the original. – Mario Jan 18 '17 at 12:43
  • @Mario whelp...of course you're right. OP: don't ever do that! ;) – Lenniey Jan 18 '17 at 12:45
  • 1
    @Lenniey - The copy needs to go the other way! And if you can copy, then you can link. – AFH Jan 18 '17 at 12:50
  • @AFH yeah my comment is a complete mess... – Lenniey Jan 18 '17 at 13:16
13

You get this message because of Apple's System Integrity Protection. System Integrity Protection includes protection for these parts of the system:

/System
/usr
/bin
/sbin
Apps that are pre-installed with OS X

Paths and apps that third-party apps and installers can continue to write to include:

/Applications
/Library
/usr/local

This means that you can simply create a symbolic link in /usr/local/bin (it's still in your $PATH).

BUT, it seems that you specifically need to create the symbolic link in /usr/bin. You can achieve it by disabling System Integrity Protection (please don't do it, just edit the scripts..). You can disable it by (I haven't tested it myself!!!):

Click the  menu.
Select Restart...
Hold down command-R to boot into the Recovery System.
Click the Utilities menu and select Terminal.
Type csrutil disable and press return.
Close the Terminal app.
Click the  menu and select Restart....
  • 2
    You've missed the point: the questioner has scripts which specify #!/usr/bin/zh as the shell, so the solution he seeks is to link this location to where the shell actually resides, but as you say he is protected from doing this. Unless the protection is bypassed, the only solution would seem to be a batch edit of the scripts. – AFH Jan 18 '17 at 12:45
  • Well yes, you're correct, he has to edit the scripts (which can happen with a single command). – 13dimitar Jan 18 '17 at 12:47
  • @Dimitar look at the question: Is there a better way to achieve my original goal? Note that fixing the #! lines is not an option. – Lenniey Jan 18 '17 at 12:58
  • 1
    note taken, I've modified my answer – 13dimitar Jan 18 '17 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.