Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone (private) Github repo to EC2

I'm trying to clone a private Github repo to a new Amazon EC2 (Ubuntu) instance.

The EC2 Instance fails to git clone <PATH> due to

[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Here's my steps:

  1. Run ssh-keygen on local machine
  2. Add the newly generated public key (~/.ssh/id_rsa.pub) into GitHub 'SSH Keys' section
  3. Also import that public key into the EC2 'Key Pairs' dashboard
  4. Make the instance ensuring that new Key Pair is used during launch
  5. log into EC2 instance, update yum and yum install git etc
  6. Try git clone <PATH> but get permission error. Works fine on local machine...

I'm not fully understanding how EC2 is using my Key Pair... why doesn't GitHub recognize the EC2 instance?

like image 335
1owk3y Avatar asked Oct 19 '25 11:10

1owk3y


1 Answers

"Also import that public key into the EC2 'Key Pairs' dashboard"

That only allows you to use that key pair for SSH into EC2 instances. And only instances that you create after you add that key pair to AWS. That key pair management dashboard has nothing to do with the git command you are running on the EC2 server.

You need to copy your local ~/.ssh/id_rsa private key file to that same location on the EC2 server.

like image 56
Mark B Avatar answered Oct 21 '25 08:10

Mark B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!