57

我正在使用 SSH 将 git repo 克隆到我的 Web 服务器,但每次我收到此错误

$git clone git@github.com:aleccunningham/marjoram.git
Cloning into marjoram...
Host key verification failed.

我已经尝试了几乎所有在谷歌搜索中出现的东西,我对为什么这不起作用感到目瞪口呆。有任何想法吗?

另外,我没有使用像 Jenkins 这样的东西。

4

4 回答 4

202

问题可能是您的 ~/.ssh/known_hosts 文件中不存在 Github。

将 GitHub 附加到授权主机列表中:

ssh-keyscan -H github.com >> ~/.ssh/known_hosts

于 2015-04-01T00:07:54.457 回答
21

已解决问题...您需要将 ssh 公钥添加到您的 github 帐户。

  1. 验证 ssh 密钥是否已正确设置。
    1. ssh-keygen
    2. 输入密码(保持默认路径 - ~/.ssh/id_rsa
  2. 公钥 ( ~/.ssh/id_rsa.pub) 添加到 github 帐户
  3. 试试git clone。有用!


初始状态(公钥未添加到 git hub 帐户)

foo@bn18-251:~$ rm -rf test
foo@bn18-251:~$ ls
foo@bn18-251:~$ git clone git@github.com:devendra-d-chavan/test.git
Cloning into 'test'...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
foo@bn18-251:~$


现在,将公钥添加~/.ssh/id_rsa.pub到 github 帐户(我使用过cat ~/.ssh/id_rsa.pub

foo@bn18-251:~$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/foo/.ssh/id_rsa): 
Created directory '/home/foo/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/foo/.ssh/id_rsa.
Your public key has been saved in /home/foo/.ssh/id_rsa.pub.
The key fingerprint is:
xxxxx
The key's randomart image is:
+--[ RSA 2048]----+
xxxxx
+-----------------+
foo@bn18-251:~$ cat ./.ssh/id_rsa.pub 
xxxxx
foo@bn18-251:~$ git clone git@github.com:devendra-d-chavan/test.git
Cloning into 'test'...
The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts.
Enter passphrase for key '/home/foo/.ssh/id_rsa': 
warning: You appear to have cloned an empty repository.
foo@bn18-251:~$ ls
test
foo@bn18-251:~/test$ git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
于 2013-03-05T04:29:18.657 回答
0

好吧,从 sourceTree 我无法解决这个问题,但我从 bash 创建了 sshkey,至少它可以从 git-bash 工作。

https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html

于 2018-11-20T19:59:23.217 回答
-1

我也遇到了同样的问题,解决方法很简单,从cmd或者其他windows命令行工具改成git bash就可以了。Windows 有时无法很好地处理 git npm 依赖项。

于 2016-06-01T22:27:39.310 回答