For no known reason I suddenly have to execute most terminal commands using sudo. For example, I have always been able to run "git pull/push" etc. without any trouble. Now, I get "permission denied". Is there any way of resetting the permissions to default? I'm using OS X Yosemite.

2 Answers 2


As in the first answer you have run various commands with the elevated command, sudo, in your personal space. Now you have directories in your personal space that are owned, not by you, but by root. If you type cd with no parameters you'll be taken to the bottom of your personal space (where it starts) and be able to see it with the pwd command.

On many system by default your personal space will be /home/[your username].

You can fix this have to execute most terminal commands using sudo by recovering access to your whole home directory.

Do this by first going to your home directory, then back out a level with cd ...

Now execute this command:

$ sudo chown -R [your username] [your username]

If your username is ljames you can do this with this sequence:

$ cd ~ljames
$ cd ..
$ sudo chown -R ljames ljames

There are a number of ways to do this. I went thought those details to help you to see where the changes are taking place. You can effectively do this in one command line with:

$ sudo chown -R ljames ~ljames

Now when you are working in your own personal space you shouldn't get the permission denied errors. You should only be denied permission when you're working outside your personal area in what is called system wide. You'll have to use the elevated command sudo to make changes in those areas.

  • Thank you, that solves the problem! Any ideas how the permissions could have been changed in the first place? Seems a bit scary...
    – user1337
    Oct 25, 2014 at 13:53
  • 1
    Yes. It's the first line of my answer. I'll elaborate more if it's still not clear. Oct 25, 2014 at 13:55

This will depend on the permissions of the folders/files you are trying to modify and not on the commands themselves. You probably ran a git command as sudo once and that changed the ownership to root. I could give you a more specific answer if you posted the output of ls -l on your git repository.

Assuming the problem is what I described above, you can fix it by changing the ownership back to your user (replace UserFoo with your actual user name):

chown -R UserFoo /path/to/git/folder 
  • Ok, here's the output: drwxr-xr-x 5 root staff 170 20 Okt 13:07 data -rw-r--r--@ 1 Erik staff 21 17 Okt 14:26 hello.m -rw-r--r-- 1 root staff 2282 24 Okt 15:37 hello.py -rw-r--r-- 1 Erik staff 24 17 Okt 15:25 import csv -rw-r--r-- 1 root staff 4619 24 Okt 15:33 result.txt -rwxr-xr-x 1 Erik staff 117234 8 Okt 11:13 testing.csv However, this is not exclusive to git. I have the same problem with most commands which used to work previously.
    – user1337
    Oct 25, 2014 at 13:23
  • @user89161 please edit your question to add extra information, it is hard to read and easy to miss in the comments. That said, the issue is indeed what I suspected and my answer should solve it. Note the root in the output, that means that the files belong to root and you don't have access to them. The command I gave will change the ownership back to your user.
    – terdon
    Oct 25, 2014 at 13:35

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.