0

We have a server with some of our git repositories on and I would like to be able to clone one to our webserver (which runs debian). I ran ssh-keygen on the webserver and copied the public key into authorized_keys on the gitserver and so now I can successfully ssh to the gitserver from the webserver:

ssh -T [email protected]

And it will log me in. However, if I call git clone on the webserver:

sudo git clone [email protected]:/dir/repo.git

I get this response:

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

Does anyone know why this is happening? I read that I should allow ForwardAgent in /etc/ssh_config on my local machine (running Max OS X), which I've done but didn't fix the issue.

1 Answer 1

2

You're not calling git clone; you're calling sudo which switches to a completely different Unix account (root) and only then calls git clone.

The result, as you'd also notice with sudo ssh -v ..., is that ssh is looking for private keys in directories belonging to root, not you. Since sudo cleans the environment by default, ssh cannot use your SSH agent either, as the SSH_AUTH_SOCK environment variable gets removed.

As you have agent forwarding enabled, try sudo -E ssh ... to make it preserve all environment variables.

2
  • Ah very true. Doh!
    – ingh.am
    Jun 27, 2014 at 16:40
  • I've just shut down the test servers, but I will try that later tonight. Thanks
    – ingh.am
    Jun 27, 2014 at 16:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .