Permission denied on Git config file
Symptoms
When trying to push to a Repository
the following error occurs:
<USER>$ git push origin master
Password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 216 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: warning: unable to access '/home/<USER>/.config/git/config': Permission denied
remote: warning: unable to access '/home/<USER>/.gitconfig': Permission denied
remote: warning: unable to access '/home/<USER>/.config/git/config': Permission denied
remote: warning: unable to access '/home/<USER>/.gitconfig': Permission denied
remote: warning: unable to access '/home/<USER>/.config/git/config': Permission denied
remote: warning: unable to access '/home/<USER>/.gitconfig': Permission denied
To https://<USER>@<HOST>/scm/TEST/test.git
Creating a repository fails with the following error in the atlassian-stash.log
:
2014-04-28 15:49:33,094 DEBUG [http-bio-7990-exec-66] admin 949x1214x0 ykug2q 192.168.1.21,127.0.0.1 "POST /projects/TST/repos HTTP/1.1" c.a.s.i.r.RepositoryServiceImpl Could not create repository TST/test [5]
com.atlassian.stash.exception.ServerException: An error occurred while executing an external process: '/usr/bin/git init --bare --quiet --shared=false /home/<USER>/atlassian/application-data/stash/data/repositories/5' exited with code 128 saying: fatal: unable to access '/root/.config/git/config': Permission denied
at com.atlassian.stash.scm.git.common.command.GitCommandExitHandler.evaluateThrowable(GitCommandExitHandler.java:115) ~[na:na]
at com.atlassian.stash.scm.git.common.command.GitCommandExitHandler.onError(GitCommandExitHandler.java:158) ~[na:na]
at com.atlassian.stash.scm.DefaultCommandExitHandler.onExit(DefaultCommandExitHandler.java:33) ~[stash-spi-2.12.1.jar:na]
at com.atlassian.stash.scm.BaseCommand.callExitHandler(BaseCommand.java:143) ~[stash-spi-2.12.1.jar:na]
at com.atlassian.stash.scm.BaseCommand$CommandFuture.internalGet(BaseCommand.java:256) ~[stash-spi-2.12.1.jar:na]
...
Caused by: com.atlassian.utils.process.ProcessException: Non-zero exit code: 128
Cause
- Git reads
config settings
from a variety of paths and the<USER>
doesn't have access to some of them. Git tries to read
root config setting
instead of<USER>
config settings due to the starting script using su command with do not reset environment variables option (-m):/bin/su -m $USER -c "cd $BASE/logs && $BASE/bin/startup.sh &> /dev/null"
- Stash is being started as
root
with/etc/init.d/atlstash start
script. Since theinit.d
script callsstart-stash.sh
which usessu -m
this causes the environment variables forroot
to be preserved andatlstash
does not have permission to write in theroot
home directory.
Resolution
Fix the permissions on the files and directories with regard to the Stash user performing the command:
chown <USER>.<GROUP> -R /home/<USER>/.config chown <USER>.<GROUP> -R /home/<USER>/.gitconfig
Change the
USER
.GROUP
by your username and group in your OS.If Stash starting script have su command, make sure that the option -m is not used.
If Stash is being started with
/etc/init.d/atlstash start
switch to starting Stashing withservice atlstash start
To have Stash automatically start at boot, run
chkconfig atlstash on