12

In our Ubuntu Server we are able to clone as Nginx user in /usr/share/nginx/www that has www-data:www-data ownership getting a warning as

” warning: unable to access '/root/.config/git/attributes': Permission denied”

We are executing the command as sudo -u www-data git clone <repo>.

With sudo we are getting this warning otherwise its working fine.

We are able to clone as root user and there is no issue.

.gitconfig is located in only root and please see the contents:

root@geo:~# cat /root/.gitconfig [user] name = pc_user email = [email protected] root@geo:~# 

Can anyone please help us on it.

We tried various option like manually created /root/.config/ directly and changed permission etc.. but nothing is working. Can anyone please help me on it.

Also please see this:

root@geo:/setup/test# ll /setup/ total 16 drwxr-xr-x 4 www-data www-data 4096 Oct 9 00:14 ./ drwxr-xr-x 24 root root 4096 Oct 9 00:14 ../ drwxr-xr-x 3 www-data www-data 4096 Oct 9 00:14 test/ root@geo:/setup/test# sudo -u www-data git clone -v git@....../test.git Cloning into 'test'... remote: Counting objects: 8323, done. remote: Compressing objects: 100% (6459/6459), done. remote: Total 8323 (delta 1543), reused 8241 (delta 1500) Receiving objects: 100% (8323/8323), 39.85 MiB | 19.52 MiB/s, done. Resolving deltas: 100% (1543/1543), done. Checking connectivity... done. warning: unable to access '/root/.config/git/attributes': Permission denied 

So it seems an issue with git setup. Can any one please guide us.


I am using this setup on an Ubuntu 14.04. When I do the same setup in another Ubuntu 12.04 its perfectly working fine.

Also I done this:

Created an user geopc and added to sudoers list and when we logged as geopc user and do this command sudo -u www-data git clone -v git@....../test.git its working perfectly.

So the issue is when we directly logged as root user in Ubuntu 14.04 and do clone as sudo -u www-data git clone this warning comes. But its not in Ubuntu 12.04.

We are using git version 1.9.1 on Ubuntu 14.04 we also upgraded git to version 2.1.1 but same.

4
  • 1
    It is fairly typical that file system permissions block all other users, including www-data, from accessing files under /root. If not the file-system permissions than certainly things like AppArmor or SELinux should block webserver access to /root. Commented Oct 8, 2014 at 14:52
  • It seems not.. I modified the question please have a check. Commented Oct 9, 2014 at 4:25
  • duplicate stackoverflow.com/questions/27150926/… Commented Mar 3, 2015 at 12:13
  • I'm using this answer and this answer working for me. Try yourself Commented Jun 28, 2019 at 10:04

3 Answers 3

12

@mu is right. This is an issue of your the HOME environment variable of user root being passed to the script instead of user www-data's HOME environment variable.

You just need to add the -H switch to the sudo command though, so it's fairly easy:

sudo -u www-data -H git clone -v git@....../test.git 
1

I think the HOME variable is set up incorrectly.

From 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

1
  • for me it was starting: HOME=/home/git git daemon ... Commented Mar 3, 2015 at 12:06
-1

You just need to restart your stash instance using user other then root. Typically, user would be same as you have used at the time of installation.

e.g. atlstash

Doing this will set your HOME variable as /home/atlstash and resolve your issue

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.