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

  • EC2 can't SSH into github
  • Git post-receive hook not running following push
  • Can't push to repository on EC2 - Could not resolve hostname
  • Permission denied (publickey) when pushing commit to amazon ec2
  • SSH into EC2 and can't execute git clone command
  • git: 'aws.push' is not a git command when trying to push a repository to Amazon Elastic Beanstalk on Mac
  • 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?

  • svn2git cryptic error
  • Git through a Proxy. What is causing the 407 error when cloning?
  • See diff between current state and last commit
  • SSH key stop working on MAC OS Sierra 10.12.3 in source tree
  • What does this quote about git rebase mean?
  • git - merge conflict when local is deleted but file exists in remote
  • 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.