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:
- Run
ssh-keygen
on local machine - Add the newly generated public key (
~/.ssh/id_rsa.pub
) into GitHub 'SSH Keys' section - Also import that public key into the EC2 'Key Pairs' dashboard
- Make the instance ensuring that new Key Pair is used during launch
- log into EC2 instance, update
yum
andyum install git
etc - 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?
CodePudding user response:
"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.