54

I have got a virtual private server with nginx Virtual Hosts setup (Server Blocks).

I've installed Git and got my ssh keys authenticated with GitHub.

I have my website running in

 ~/var/www/example.com/public_html/

I tried to run:

git clone git@github.com:example/example.co.uk.git

to pull my files on GitHub to the /public_html/ directory but I get the error:

fatal: could not create work tree dir 'example.com'.: Permission denied

I've followed this tutorial including the same issue he has mentioned on the page, but it still won't work: http://machiine.com/2013/pulling-a-git-repo-from-github-to-your-ubuntu-server/

I'm completely new to this, so your help would be much appreciated!

AMIC MING
  • 6,306
  • 6
  • 46
  • 62
David Ingledow
  • 2,025
  • 4
  • 20
  • 36
  • 2
    Well, if it says "Permission denied", it basically means it. Are you sure that the the permissions are correct? Can you create directories in the directory where you attempt to clone the repository to? – Paweł Duda Nov 29 '13 at 01:07
  • 2
    When you say you're "completely new to this", new to what? Git? Virtual hosts? Unix directory permissions? User accounts? – Greg Hewgill Nov 29 '13 at 02:12
  • @PawełDuda Yeah, I have made a directory called 'test' in /public_html/ no problem. – David Ingledow Nov 29 '13 at 08:17
  • @GregHewgill I'm new to all of it really, I've just followed tutorials on DigitalOcean so far, but really stuck on this – David Ingledow Nov 29 '13 at 08:18
  • can you do a "ls -l" inside your work /var/www directory and paste the output into your post? – Paweł Duda Nov 29 '13 at 11:41
  • as a clarification @DavidIngledow is trying to clone *into* `~/var/www/example.com/public_html/` but doesn't have permission for the target. On my first reading I thought the problem was a lack of permissions in the git source (which in my case was a local folder). – geneorama Aug 13 '14 at 19:14

11 Answers11

134

I think you don't have your permissions set up correctly for /var/www Change the ownership of the folder.

sudo chown -R $USER /var/www

Jon Winstanley
  • 23,010
  • 22
  • 73
  • 116
Wil
  • 1,778
  • 1
  • 16
  • 15
  • I've learnt a lot since then and it was a permissions problem. This would have fixed it, but in this case I actually just deleted everything and started again. – David Ingledow Apr 18 '14 at 09:55
  • 3
    Not sure about your username, Hit `sudo chown -R $USER /var/www` cheers ;) – Lalit Mohan Aug 12 '20 at 06:20
10

I was facing the same issue but it was not a permission issue.

When you are doing git clone it will create try to create replica of the respository structure.

When its trying to create the folder/directory with same name and path in your local os process is not allowing to do so and hence the error. There was "background" java process running in Task-manager which was accessing the resource of the directory(folder) and hence it was showing as permission denied for git operations. I have killed those process and that solved my problem. Cheers!!

Ashutosh Kumar
  • 301
  • 3
  • 10
10

Turns out the problem was in the permission. I fix it with the following command

sudo chown -R $USER /var/www

Please make sure with the $USER variable. I tested and worked on Ubuntu Distro

Lalit Mohan
  • 2,685
  • 2
  • 16
  • 16
7

I was facing same issue then I read first few lines of this question and I realised that I was trying to run command at the root directory of my bash profile instead of CD/my work project folder. I switched back to my work folder and able to clone the project successfully

4

You should logged in not as "root" user.

Or assign permission to your "current_user" to do this by using following command

sudo chown -R username.www-data /var/www

sudo chmod -R +rwx /var/www

Piyush Bansal
  • 1,635
  • 4
  • 16
  • 39
4
  1. Open your terminal.
  2. Run cd /
  3. Run sudo chown -R $(whoami):$(whoami) /var

Note: I tested it using ubuntu os

RobC
  • 22,977
  • 20
  • 73
  • 80
1

Change ownership and permissions folder

sudo chown -R username.www-data /var/www

sudo chmod -R +rwx /var/www
Michal Čihař
  • 9,799
  • 6
  • 49
  • 87
Jirson Tavera
  • 1,303
  • 14
  • 18
1

Tested On Ubuntu 20, sudo chown -R $USER:$USER /var/www

Ashwani Garg
  • 1,479
  • 1
  • 16
  • 22
1

Here you don't have administration permission. Run the terminal as "Run as administrator" in windows

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 25 '22 at 14:38
0

Most common reason for this error is that you don't have permission to create file in the current directory. Ensure you are in the right directory. try this on mac system to list the directory

ls, then cd right_folder_name

trustidkid
  • 577
  • 4
  • 6
0

I am truly new to this. I just ran the command on the home directory. It shows a permission error.

fatal: could not create work tree dir 'product-catalog-js': Permission denied

Referred above solutions, I understand this is a directory issue.

So I changed the directory to c/xampp/htdocs/. After running the below command, it's working fine. I cloned the repo successfully.

$ git clone https://github.com/contentful/product-catalogue-js.git

Output: /c/xampp/htdocs/product-catalogue-js (master)

DSDmark
  • 1,045
  • 5
  • 11
  • 25
Babu A
  • 11
  • 4