I can connect from my pc to my EC2 git server using ssh ( i specified port 22 cause default port is onother):
$ ssh -p22 [email protected]
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://[email protected]:22/home/dev/some/stuff.git
this is the output:
[email protected]: Permission denied (publickey).
why????
The reason is because you're using
sudo. OpenSSH uses the public keys of the current user to log in, and when you usesudo, they're the public keys ofroot, 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/configfile that uses the normal user's keys via theIdentityFileoption. For example, if your normal user isexampleand you're using an Ed25519 key, the file might look like this: