MacOS – Why is the /usr/local/bin only accessible by root user? Which rights to fix it

macos

I recently wanted to use pod to update the path of a framework.

Cocoapods is installed and can be find here :

/usr/local/bin/

But surprise! It is set to root only access :

ls -l /usr/local
drwx------   504    wheel  bin/
drwxr-xr-x@  john   staff  include/
drwxr-xr-x@  john   staff  lib/
drwxr-xr-x   root   wheel  share/

So I can't use pod because in any case :

  • pod install realm

    heeeyy dude, you can't access pod cause you are not root .!.

  • sudo pod install realm

    heeeyy dude, you can’t use pod as a root! .!.

I feel that this folder shouldn't be set as 'root only' because:

I know Linux isn't a BSD but still, it doesn't look that much different no o.O


Finally here are my questions:

  • I searched and there is no user with the uid 504, is this suspicious?

(I checked it with ""dscacheutil -q user | grep 504"")

  • What are suposed to be the rights and owner on the folder?

  • Is there someone who had the same problem?

  • Any idea about why this happened?

Best Answer

The default setup for /usr/local is shown here

~ $ ls -ld /usr/local
drwxr-xr-x@ 3 root  wheel  102  5 Aug 20:01 /usr/local 

this means that files and directorries under /usr/local can only be created by the root user e.g. my /usr/local has

~ $ ls -l /usr/local
total 0
drwxr-xr-x  12 root  wheel  408 11 Sep 12:11 bin

So your share directory looks normal but the others have odd changes

include and lib look like you changed the permissions of /usr/local so you could write to it and then created these two directories (The most common setup like that is installing Homebrew) (we need to see what ls -ld /usr/local shows.

As for bin there must have been several things. First a new user must have been added at some time, normal users (created through the System Preferences GUI start at 501) e.g. I am the second user and so my id is 502 and then the directory was created or chowned to that user- or the directory was created elsewhere and then moved as root to where it is.
Separately the permissions of the directory have been changed by chmod 700

So the correct setting is as per /usr/local/share unless you are using Homebrew in its default install and then they should be like /usr/local/include