1

This is my setup.

  1. My git repository is in bitbucket
  2. I have created keys on my remote aws ec2 server and kept it in ~/.ssh folder
  3. I then add the key via the ssh-agent on my remote server
  4. Updated these keys on the bitbucket website.

When I login to my remote server and run git pull on my git repository everything works fine. No issues here.

But when I run the same the same via the cygwin bash on windows it gives me this error:

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

I do the following on my windows machine

ssh -i xyz.pem user@ip -t 'sudo sh deploy.sh'

Where the deploy.sh, cd's into my repository and does a git pull.

Why is this issue happening ? Should I also keep these ssh keys on my windows machine? Any help will be invaluable.

chicks
  • 3,793
  • 10
  • 27
  • 36
sp497
  • 115
  • 3

1 Answers1

4

By running sh with sudo, you are effectively using the root's .ssh credentials to access the repo. Those do not match with the key you generated and added to bitbucket.

I wonder why you would need sudo in the first place, is the repo only writable by root? One option would be to add root's ssh key to bitbucket, or to refrain from using sudo.

chicks
  • 3,793
  • 10
  • 27
  • 36
Michael
  • 280
  • 3
  • 16