Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git unable to create file permission denied

Tags:

git

linux

ubuntu

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?

like image 455
max_ Avatar asked Aug 22 '12 16:08

max_


People also ask

How do I fix Permission denied in git?

In terminal enter this command with your ssh file name pbcopy < ~/. ssh/id_rsa. pub This will copy the file to your clipboard Now open you github account Go to Settings > SSH and GPG keys > New SSH key Enter title and paste the key from clipboard and save it. Voila you're done.

Why do I get permission denied in Git bash?

Conclusion. The Bash permission denied error indicates you are trying to execute a file which you do not have permission to run. To fix this issue, use the chmod u+x command to give yourself permissions. If you cannot use this command, you may need to contact your system administrator to get access to a file.

Can not create directory permission denied?

If you receive an error telling you that you do not have permissions to create a directory or to write a file to a directory, this is likely an indication that your script is attempting to write to a directory that you do not own.

Does GIT change file permissions?

Git tracks exactly one bit of permission: executable or not executable. You don't say what you mean precisely by "it stopped taking file permission changes into account", but my best guess is that you didn't change the executable permission, and so from Git's point of view, there was no change to take into account.


3 Answers

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
like image 20
Frank Forte Avatar answered Sep 30 '22 03:09

Frank Forte


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?

like image 90
Peerkon Avatar answered Sep 30 '22 03:09

Peerkon


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).

like image 25
Nate C-K Avatar answered Sep 30 '22 04:09

Nate C-K