1

I am new to AWS and followed a tutorial to set up git in aws and the push my local files into it. I have a Key with me with .pem extension which got generated while I was creating the instance. I have added the remote repository like this: git remote add production ssh://root@35.154.37.131/var/repo/site.git

after this when I tried to push into the repository I got:

 $ git push production master
Permission denied (publickey).
fatal: Could not read from remote repository.

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

I googled but not able to follow the solutions. However, I could ssh to my instance using:

ssh -i wexpert_instance_2.pem ubuntu@ec2-35-154-37-131.ap-south-1.compute.amazonaws.com

please help.

Suraj Jeswara
  • 446
  • 2
  • 10
  • 23
  • You may find https://superuser.com/questions/232373/how-to-tell-git-which-private-key-to-use useful. – msbit Jul 29 '18 at 05:22
  • Or try this one: https://stackoverflow.com/questions/4565700/specify-private-ssh-key-to-use-when-executing-shell-command – moilejter Jul 29 '18 at 05:22
  • And you may want to ensure the username matches (`root` in your original remote command vs `ubuntu` in your ssh command). – msbit Jul 29 '18 at 05:23
  • @msbit is right, you're probably using the wrong user as well as not using the public DNS. Try changing the remote to use: `ssh://ubuntu@ec2-35-154-37-131.ap-south-1.compute.amazonaws.com/var/repos/site.git` – Brian Lee Jul 29 '18 at 06:03
  • @DigitalDrifter I tried doing `git remote add production ssh://ubuntu@ec2-35-154-37-131.ap-south-1.compute.amazonaws.com/var/repos/site.git` But still getting the same issue. – Suraj Jeswara Jul 29 '18 at 06:09

1 Answers1

0

I tried doing git remote add production ssh://ubuntu@ec2-35-154-37-131.ap-south-1.compute.amazonaws.com/var/repos/site.git

That is expected, because SSH will look for your key in ~/.ssh/id_rsa by default.

Since you don't have a default key, you need to define a ~/.ssh/config file (chmod 644), with:

Host myaws
Hostname ec2-35-154-37-131.ap-south-1.compute.amazonaws.com
User ubuntu
IdentityFile /full/path/to/wexpert_instance_2.pem

Then:

git remote set-url production myaws:/var/repo/site.git
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250