-1

I can connect from my pc to my EC2 git server using ssh ( i specified port 22 cause default port is onother):

$ ssh -p22 dev@xxxxxxxxxxxx.compute.amazonaws.com

this works fine, but when I try to clone I have som problems(again i specified port 22 cause default port is onother):

sudo git clone ssh://dev@xxxxxxxxxx.compute.amazonaws.com:22/home/dev/some/stuff.git

this is the output:

dev@xxxxxxxxxxxxxxxxxx.compute.amazonaws.com: Permission denied (publickey).

why????

matQ
  • 597
  • 2
  • 13
  • 27
  • Does this answer your question? [How to solve Permission denied (publickey) error when using Git?](https://stackoverflow.com/questions/2643502/how-to-solve-permission-denied-publickey-error-when-using-git) – GoodDeeds Nov 21 '19 at 22:01
  • Possible duplicate of [Git Clone : Permission denied (publickey). fatal: Could not read from remote repository](https://stackoverflow.com/questions/38221255/git-clone-permission-denied-publickey-fatal-could-not-read-from-remote-rep) – phd Nov 22 '19 at 00:03
  • https://stackoverflow.com/search?q=%5Bgit%5D+sudo+Permission+denied+publickey – phd Nov 22 '19 at 00:03
  • https://help.github.com/en/github/authenticating-to-github/error-permission-denied-publickey#should-the-sudo-command-be-used-with-git – phd Nov 22 '19 at 00:03

1 Answers1

1

The reason is because you're using sudo. OpenSSH uses the public keys of the current user to log in, and when you use sudo, they're the public keys of root, not your normal user.

If you want to clone as root, you either need to set up keys for root or set a /root/.ssh/config file that uses the normal user's keys via the IdentityFile option. For example, if your normal user is example and you're using an Ed25519 key, the file might look like this:

Host xxxxxxxxxx.compute.amazonaws.com
    IdentityFile /home/example/.ssh/id_ed25519
bk2204
  • 64,793
  • 6
  • 84
  • 100