3

I am connecting from a Ubuntu laptop to a virtual machine via ssh.

Within this VM, I am trying to git clone a repository with:

/home/httpd$ sudo git clone git@github.com:NexwayGroup/softgallery
[sudo] password for jverstrynge: 
Cloning into 'softgallery'...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

I have seen this SO question and the solution suggests modifying the git config with:

/home/httpd$ git config http.postBuffer 524288000
error: could not lock config file .git/config: No such file or directory

But I am getting the above error. Anyone knows how to solve this one?

I have checked the connection using github instructions and it seems fine:

ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.
Enter passphrase for key '/home/jverstrynge/.ssh/id_rsa': 
Hi JVerstry! You've successfully authenticated, but GitHub does not provide shell access.
jverstrynge@devjverstrynge:/home/httpd$ 
Community
  • 1
  • 1
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453

2 Answers2

4

You are running

sudo git clone

sudo runs the command as root, but your root probably does not have your private SSH key. Therefore, the connection can't be established.

A solution would be to either run the git command as your normal user (without sudo) or, if sudo is really needed for some reason, add the SSH key for root, too.

taskinoor
  • 45,586
  • 12
  • 116
  • 142
Elias Holzmann
  • 3,216
  • 2
  • 17
  • 33
  • I ran in sudo, because it could not create the clone directory with my profile. Thing is, we changed the ownership of the /home directory from root to jverstrynge and problem was solved. Did not need to use sudo anymore. – Jérôme Verstrynge Dec 14 '15 at 13:35
  • This might be dangerous because of security reasons. With those permissions, you could delete and replace home directories belonging to other users. Besides, why do you clone into /home? If you really need to, you could create the empty directory for the repo as root, set permissions for you to write and then clone into it. Of course, it is depending in your specific setting whether this is really necessary. – Elias Holzmann Dec 14 '15 at 15:33
1

One possible solution would be to setup your git host in ~/.ssh/config of the root user and use the ssh key from your user which has the git public, private key. A bit hacky, but should work.

Thus, add the following to /root/.ssh/config:

Host github.com
  Hostname github.com
  User jverstrynge
  IdentityFile  /home/jverstrynge/.ssh/id_rsa

and then you should be able to do a sudo git clone git@github.com:NexwayGroup/softgallery since the sudo should cause root user's .ssh/config to be used

Ashutosh Jindal
  • 18,501
  • 4
  • 62
  • 91