Changing Ownership of a directory in OS X - macos

I've installed homebrew, and am trying to change the write permissisons for the /usr/local/include directory.
When I run 'brew doctor', I get this error message:
Error: The /usr/local directory is not writable. Even if this
directory was writable when you installed Homebrew, other software may
change permissions on this directory. Some versions of the "InstantOn"
component of Airfoil are known to do this.
You should probably change the ownership and permissions of /usr/local
back to your user account.
I tried doing that with chown, but I'm pretty new at this and don't think I was running it correctly. I ran:
chown myusername /usr/local/include
I didn't get any error message, but when I run brew doctor it says I still lack permission to write to /usr/local/include.
Any help would be greatly appreciated!
Edit:
I'm getting an "operation not permitted" error.
cd /usr
chown myusername local
chown: local: Operation not permitted

Simple solution that worked for me:
click on your background to go to finder
click on go and go to folder /usr
right click on local and do get info
unlock the lock at the bottom
click + sign and add your user to the list and give read/write privileges
click on the gear sign at the bottom and choose apply to enclosed items to recurse under that directory and assign privileges too all directories beneath it.
type brew doctor from command prompt to test. My result:
Your system is ready to brew.

On my system, /usr/local is owned by root:admin and is rwxrwxr-x. My user is a member of the admin group, thus has write permissions. I haven't messed with ownership and permissions there, and my Homebrew installation is not complaining, so I assume my setup fits its requirements.
Check the ownership of your /usr/local; if it is owned by group admin, check if your non-adminsitrator account is a member of that group.

You should use: sudo chown username folder

Be careful with the change of ownership
Do not try to change ownership for /usr/ or recursively for /usr/local/
if you are not getting the same error posted in the original question.
You could screw up your system or weakness its security.
Some users can receive with homebrew permission errors that could be solved without changing the ownership of the whole /usr/ or /usr/local/ directories.
According to my experience, in most cases, it is just enough to restore the ownership for /usr/local/Cellar:
sudo chown -R "$USER" /usr/local/Cellar/
Alternatively, if you have a not standard installation
sudo chown -R "$USER" "$(brew --prefix)/Cellar"

You can try use command ls -l. With this command you will see list of files in current directory with some useful information, like who is owner of this file. So you will see if chown worked out. I believe that chown is a right command for changing ownership.

Exactly this problem has just started occuring on my MacBook.
The owner of /usr/local is:
drwxr-xr-x 24 root wheel 768 Apr 9 17:25 local
I am unable to change the permissions and add myself via Finder - I get a "you don't have the necessary permission" error.
Is this maybe due to security changes in mac os? (I have 10.13.6)

Related

Fix Home Brew permissions on High Sierra

I accidently tried renamed my home folder on my mac. Never. Ever. Do. That! Homebrew no longer works... I get this error no matter what I try to install (or another github address).
Error: Permission denied # rb_sysopen - /private/tmp/github_api_headers20180921-5820-13099yc.
Nothing works, not even wget or mysql.
I tried uninstalling / re-installing but doesn't work.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
How can I fix homebrew? Is it necessary to wipe the whole computer?
Files under /Users/myuser should have ownership to myuser and group ownership to staff.
I don't know your specific settings but before to wipe out your system you could try to restore these basic ownerships with:
chown -R myuser:staff /Users/myuser
where myuser is the name of your user. As I said, I don't know anything about your specific settings so do this at your own risk.

Operation not permitted and permission denied

My mac version is 10.12.2.
I'm trying to install R studio and a number of other softwares, but it doesn't work. I suspect it's because of permission issues - my mac doesn't allow them to create directories during installing.
~$ pwd
/Users/biona001
~$ mkdir fdsa
mkdir: fdsa: Operation not permitted
but if I'm in a higher director, it says something different
~$ cd ../
Users$ pwd
/Users
Users$ mkdir fdsa
mkdir: fdsa: Permission denied
and if I move into a lower directory, it works
Users$ cd biona001/Documents/
Documents$ mkdir fdsa
Documents$
I googled almost everything without finding anything that worked, including the one where I boot my mac into this weird mode and type some command. I should be the administrator of this mac.
R Studio is installed by dragging the application to your applications folder. It requires R to be installed. R can be installed from a package, so you don't need the command line.
The 'administrator' on the mac, does not have permission to write files or create folders anywhere. It's not a good idea in any case.
If it's absolutely necessary, you must enable 'root' and login as root. But this is not necessary to use R Studio and R.
Enabling root access without knowing exactly what you are doing is a recipe for disaster.
I had the same "operation not permitted" issue on MacOS Sierra.
Looking at the user's home folder in Finder as John Elemans recommended, showed that the home folder was locked. Unchecked the locked checkbox in finder and was able to create a subfolder in the user's home folder via terminal.

Lost permission for sudo in OSX El Capitan

I'm new to using OSX (using El Capitan 10.11.3) and while trying to change permissions on a file using sudo, I accidentally corrupted it. Now whenever, I try to use sudo to install anything globally, I'm getting the following error message.
sudo: unable to stat /etc/sudoers: Permission denied
sudo: no valid sudoers sources found, quitting
Is there any way to solve it?
I'm also unable to even view the /etc folder
bash: cd: /etc: Permission denied
When I checked permissions on /etc folder, they are as follows
lrwxr-xr-x# 1 root wheel etc -> private/etc
I had the same issue and in my case the permissions of the root folder got corrupted. What people overlook is that / is in fact also a real, normal directory and just like every directory it has ownership and permissions. Ownership should be root:wheel and permission should be 755 (that's rwxr-xr-x).
The easiest way to restore both was starting Script Editor and then typing and running that script:
do shell script "/usr/sbin/chown root:wheel /" with administrator privileges
do shell script "/bin/chmod 755 /" with administrator privileges
You are prompted for amdin password and then chown and chmod come to the rescue. After that sudo was working again.
Disable System Integrity Protection (rootless)
Reboot the Mac and hold down Command + R keys simultaneously after you hear the startup chime, this will boot OS X into Recovery Mode
When the “OS X Utilities” screen appears, pull down the ‘Utilities’ menu at the top of the screen instead, and choose “Terminal”
Type the following command into the terminal then hit return:
csrutil disable; reboot
You’ll see a message saying that System Integrity Protection has been disabled and the Mac needs to restart for changes to take effect, and the Mac will then reboot itself automatically, just let it boot up as normal

File Permissions Issue On Mac

I'm not very familiar with Terminal / Command line on Mac, outside of basic commands (cd, ls, pwd ect.) And I was trying to install "compass" for Sass.
http://compass-style.org/install/
When I tried the first line that they give
$ gem update --system
I got an error in terminal saying that the file permissions were wrong for /usr/bin folder. So I updated that folder to 777, but then I got a warning message stating that
Insecure world writable dir /usr/bin in PATH
So I thought it didn't like that I set the permissions so high, so I updated the permissions for that folder to 744, thinking I would still be able to do what I needed..... Now I've been locked out of that folder, and I can't do much in terminal, because it seems like most commands originate from that folder? I can't change the permissions back I can't use sudo, or many other commands. It seems like a lot of the commands are located inside of the /usr/bin folder.
How can fix this? Is there a way to change the permissions back in this folder? Can I update the permissions of the /usr folder and have it modify all sub-folders?
Disk Utility's repair permissions feature should be able to fix this. Run Disk Utility, select your startup volume in the disk & volume sidebar on the left, select the "First Aid" tab on the right, then click "Repair Disk Permissions". It's possible the system is broken to the point where that can't run, but if it can run it should fix the permissions on /usr/bin.
I'm not familiar with the gem system, but in general your customizations/updates/etc shouldn't be modifying /usr/bin or anything in it. Your stuff should go someplace like /usr/local/bin, and the permissions for that can be something like 775 (never 777), and it can be assigned to the admin group so you can write to it.
try:
sudo chmod go-w /usr/local/bin
There is a post for more reference:
warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777

remove .git/index.lock': Permission denied

I'm completely stuck as to why my git has completely locked me out. I have a laptop that I use at work and when I'm home. For both accounts I use git extensively and both are located in different paths. Today I came into work and I can't do anything, all I see is:
/Applications/MAMP/htdocs/my_site/.git/index.lock': Permission denied
For all I care the branch I'm on can be deleted. I've tried removing the branch, checking out any other branch, removing the index.lock file (as suggested by other users on sites). I only have the terminal window open, no other possible programs using git (as far as I know and nothing noticeable in the activity window). I have rebooted the computer straight into my work account and still no luck. How can I remove this lock?
I had the exact same problem wanting to commit my changes to git, and solved it this way:
I needed to change the group of my .git folder and its contents:
sudo chown -R <owner>:<group> .git
needed to change the permission of this folder:
sudo chmod -R 775 .git
Check which user owns the git lock:
ls -la /Applications/MAMP/htdocs/my_site/.git/index.lock
Then you can use sudo to remove it.
After updating xcode you are maybe asked for agreeing to the new license.
git init
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
When you do this
sudo git init
you'll get a root user .git dir
drwxr-xr-x 10 root XXXX 340 25 Sep 12:40 .git
If you call other git commands which create files, these files are also created for the root user.
Change the permissions or remove .git if you don't need it yet.
=> Don't ever call git with sudo!!!
If your are asked to just call git on an empty directory
mkdir foo
cd foo
sudo git init
I had this issue as I running the following command
sudo git fetch && git checkout<branch>
Note the second sudo was missing. Running the following solved the issue:
sudo git fetch && sudo git checkout<branch>
You shouldn't have to change the owner ship of the .git directory when running sudo.
I was experiencing the same issue when trying to update the submodules of my repo:
$ git submodule update
fatal: Unable to create '.../.git/modules/deps/luajit/index.lock':
Permission denied
Unable to checkout '04dc64b558025e76a820f89a8e41840bf8269f32' in
submodule path 'deps/luajit'
It seems the problem was the submodules belonged to a different user, so I set back the ownership to me:
cd .git/modules/
chown -R user.group *
My computer system is Windows. When I open WSL remote vscode and local vscode in this path, system show this error. I closed remote vscode WSL and it solved this problem.
Change the permissions from root to the current user for the /.git folder
sudo chown username .git
Checking permission is surely the way. I faced this error when logged in with the wrong account. So, answer from my personal experience is:
"Be sure you logged in with the correct account".

Resources