Permission denied when cloning git repository

So I just setup an Amazon EC2 instance. And installed git..

sudo yum install git

I then set up my ssh key with github. Now when I try to clone my repo into /var/www/html folder i get this error..

  • Permission denied (publickey) when pushing commit to amazon ec2
  • What is the default Jenkins password?
  • Configure Jenkins EC2-Plugin with Groovy
  • AWS Deployment Failed due to “HEALTH_CONSTRAINTS”
  • Setting up a test environment for my EC2 and RDS setup
  • AWS ec2 git clone or pull not working and no error message
  • fatal: could not create work tree dir 'example.com'.: Permission denied
    

    and when I run as root…

    Cloning into 'example.com'...
    Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    

    But I made sure that my github public key matches my ~/.ssh/id_rsa.pub key. Is there something that I’m missing here?

  • Display Git commit content as a tree in console
  • Which Source Code Management System Suits My Needs Best? Git or SVN? How do you diff excel spreadsheets?
  • Best workflow when forking and renaming a GitHub project
  • how to know which commit was last checked out?
  • Is there a way to make git rerere work when the resolution is to delete the conflicted file?
  • git workflows: how to integrate and test feature branches without continuous delivery?
  • 4 Solutions collect form web for “Permission denied when cloning git repository”

    Your first error is because your user does not have access to write to /var/www/html . You could give your user permissions to do so.

    Your second error when running as root, is likely that you have your ssh keys in your user home directory, not in /root/.ssh/ , or that your .ssh directory or the ~/.ssh/id_rsa.pub key file have improber permissions. ~/.ssh/ should have the permission bits 0700 , and should have ~/.ssh/id_rsa.pub e.g. 0600

    Is the id_rsa private key in ~/.ssh/id_rsa the pair to you public key (~/.ssh/id_rsa.pub) ?

    If it’s not (or you’re not sure) I suggest you regenerate a new private/public key pair with ssh-keygen -t dsa.

    Have you tried this:

    git: fatal: Could not read from remote repository

    You can specify the username that SSH should send to the remote system as part of your remote’s URL. Put the username, followed by an @, before the remote hostname.

    git remote set-url website abc@***.com:path/to/repo
    

    My solution matches that of nos. Adding the public key of the root user fixes it. Another option would be changing the permission of the directory and executing the command as a regular user.

    Git Baby is a git and github fan, let's start git clone.