127

What does warning remote: warning: unable to access '/root/.config/git/attributes': Permission denied means and what implications does it bring?

$git clone git://git.eclipse.org/gitroot/egit/egit.git
Cloning into 'egit'...
remote: warning: unable to access '/root/.config/git/attributes': Permission denied
remote: Counting objects: 57926, done.
remote: Compressing objects: 100% (11872/11872), done.
remote: Total 57926 (delta 30734), reused 56308 (delta 29136)
Receiving objects: 100% (57926/57926), 32.29 MiB | 1021 KiB/s, done.
Resolving deltas: 100% (30734/30734), done.
Checking out files: 100% (1483/1483), done.

Should I report potential infrastructure problem to hoster?

Basilevs
  • 22,440
  • 15
  • 57
  • 102

7 Answers7

262

I ran into this situation myself. After verifying that it was looking in ~/.config/ I noticed the owner of that folder was root. I changed this to my_user_name and it worked.

cd ~/
ls -al
<Noticed .config was owned by root, unlike everything else in $HOME>
sudo chown -R $(whoami) .config

It helps to know the cause as well: This directory is created the first time you run a program that uses it. If the command was run as root, it will cause this permissions problem.

For example, if the ~/.config directory does not yet exist, and you run sudo htop, the directories ~/.config and ~/.config/htop will be created and owned by root. Afterward, a regular git command wont be able to access ~/.config and will give the above warning. (Credit: user @krethika)

The -R option with chown is to modify the permissions recursively. This will help if you have subfolders under ~/.config

starball
  • 20,030
  • 7
  • 43
  • 238
BlackVegetable
  • 12,594
  • 8
  • 50
  • 82
  • 7
    that also helped me while using linux command line inside windows 10 - thank You! – lukaszkups Jun 24 '18 at 19:14
  • Mine had subdirectories, so I had to add `-R` option to chown recursively. – thdoan Jan 07 '19 at 18:58
  • I ran into this problem just following the getting started Amazon's Lightsail node docs and this solved it perfectly, thanks – danii Mar 12 '19 at 10:01
  • Thanks a lot @BlackVegetable for this help. It helped me too. Since, I didn't have subdirectories, so I removed `-R` while changing ownership. – akgupta Jan 07 '20 at 07:55
  • @BlackVegetable Should you also specify the group with something like `sudo chown -R $(whoami):$(whoami) .config` ? – culix Feb 20 '20 at 19:50
12

I think your HOME envireonment variable is improperly set.

From the google group thread,

the HOME environment variable was set to /root so it looked at /root/.gitconfig or /root/.config/git/config since the unprivileged user didn't have access to /root it threw an error.

So the solution was for me to set the HOME env to the user's HOME directory

Community
  • 1
  • 1
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
8

Go to root directory

cd ~/

Write the following code:

sudo chown -R username /Users/username

Where username is your system's username.

Arti Prasad
  • 91
  • 1
  • 4
  • 1
    This answer to "Should i change .config folder ownership that is in my own home directory? " is relevant. https://askubuntu.com/questions/852265/should-i-change-config-folder-ownership-that-is-in-my-own-home-directory-why-i – CodingMatters Aug 25 '19 at 08:02
3

Git is trying to read config from root instead of user config. Please check your environment variables have the correct git config set or the .gitconfig file in your home folder is accessible.

Vishal
  • 2,711
  • 7
  • 33
  • 42
1

This is a problem with your user's privileges. You have to give yourself root privileges.

You can fix this problem temporarily by switching to root user. For this;

sudo su

Become root by doing it. Then you will need to add your git config settings here as well as you are migrating to a different user. For this too

git config user.email "you@example.com"
git config user.name "Your Name"

and then repeat your action again. it should work

mrcoder
  • 71
  • 3
0

I've ran the similar issue and was able to fix it on server side. git runs there under uwsgi so I added in uwsgi config the following line:

env = HOME=/srv/git

where /srv/git is owned by the same uid that uwsgi runs under and made chmod u+rwX /srv/git So, you need to point HOME variable on server side for the process that runs git to the directory where this process will have reading/writing/traverse permissions.

phaoost
  • 11
  • 2
0

For Windows, it may be a case when some process like CMD or SSH client opened some folder which Git tries to delete.

Oleg Neumyvakin
  • 9,706
  • 3
  • 58
  • 62