max_
max_

Reputation: 24481

Git unable to create file permission denied

I am using Amazon EC2 to host a website which is deployed to the server via git. I used this tutorial previously on the same kind of EC2 Ubuntu Linux Server instance, and it has worked flawlessly. However, when I try and push to the server, I receive the following error trace:

Tutorial: http://toroid.org/ams/git-website-howto

Trace:

$ git push origin master

Counting objects: 5, done.
Writing objects: 100% (3/3), 250 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: error: unable to create file index.html (Permission denied)
To ssh://[email protected]/var/www/website.git
   8068aac..04eae11  master -> master

I only have one file inside the repository at the moment, which is index.html.

The error trace is showing that the permission is being denied to create the file. Please can you tell me where I am going wrong?

Upvotes: 8

Views: 40486

Answers (4)

Akah
Akah

Reputation: 1398

Your anti virus or some ot her program may be preventing that file from being written to your folder. If you observe carefully, you would realize that all other files have been created except the one for which the permission is denied. You may be having a protection software that is preventing creation of certain file types and no matter the user type you are logged-in, the file won't be created until you disable that software.

So check that your antivirus software isn't behind this for those running windows.

Upvotes: 2

Frank Forte
Frank Forte

Reputation: 2190

FYI, I had this error because I made a hook to update files in a separate website root directory. For example:

/var/www/project.git  # (where we push updates)
/var/www/project.com  # (where the website exists)

I forgot to add the group permission to the project.com directory. This made it all work, index.html appeared in the /var/www/project.com directory once I did the next commit/push!

Full code to make it work assuming you added your user to the "developers" group:

sudo chmod -R g+ws /var/www/project_name.git
sudo chgrp -R developers /var/www/project_name.git
sudo chmod -R g+ws /var/www/project_name
sudo chgrp -R developers /var/www/project_name

And the git setting for shared repository:

git config core.sharedRepository group

Upvotes: 1

Peerkon
Peerkon

Reputation: 65

I believe if you run

 sudo chown -R git:git /srv/git/ 

this is coming from How to fix permission denied for .git/ directory when performing git push?

Upvotes: 5

Nate C-K
Nate C-K

Reputation: 5932

You probably didn't do this part of the tutorial:

First, the work tree (/var/www/www.example.org above) must be writable by the user who runs the hook (or the user needs sudo access to run git checkout -f, or something similar).

Upvotes: 4

Related Questions