Git Clone - 致命错误: 远程终端意外挂断

3

我正在使用Ubuntu笔记本通过ssh连接到一个虚拟机。

在这个虚拟机中,我正在尝试使用以下命令来克隆一个git代码库:

/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

我看到了这个SO问题,解决方案建议通过修改git配置来解决:

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

但我遇到了上述错误。有人知道如何解决吗?
我已经按照 Github 的说明 生成 SSH 密钥 并检查了连接,看起来没问题:
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$ 

1
你尝试过使用sudo检查连接吗?sudo ssh -T git@github.com?你是通过sudo克隆的。 - iltempo
@itempo 很好的发现,我没有sudo权限访问github。 - Jérôme Verstrynge
2个回答

4

你正在运行

sudo git clone

sudo命令会以root用户身份运行,但是root可能没有您的私有SSH密钥。因此,连接无法建立。

解决方案可以是以普通用户(不使用sudo)运行git命令,或者如果确实需要sudo,则也要为root添加SSH密钥。


我在sudo下运行,因为它不能用我的配置文件创建克隆目录。问题在于我们将/home目录的所有权从root改变为jverstrynge,问题得到了解决。不再需要使用sudo了。 - Jérôme Verstrynge
由于安全原因,这可能很危险。使用那些权限,您可以删除和替换属于其他用户的主目录。此外,您为什么要克隆到 /home 目录下?如果您确实需要这样做,您可以以 root 权限创建空目录用于存储代码,设置您的写入权限,然后再进行克隆。当然,这取决于您的具体设置是否真正需要这样做。 - Elias Holzmann

1

一个可能的解决方案是在root用户的~/.ssh/config中设置你的git主机,并使用拥有git公钥和私钥的用户的ssh密钥。这有点hacky,但应该可以工作。

因此,请添加以下内容到/root/.ssh/config中:

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

然后你应该能够执行 sudo git clone git@github.com:NexwayGroup/softgallery,因为 sudo 应该会使用 root 用户的 .ssh/config 文件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接