克隆 git repo 导致错误 - 主机密钥验证失败。致命:远端意外挂断

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15214977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:39:03  来源:igfitidea点击:

Cloning git repo causes error - Host key verification failed. fatal: The remote end hung up unexpectedly

gitssh-keys

提问by Alec Cunningham

I am using SSH to clone a git repo to my web server, but every time I get this error

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

$git clone [email protected]:aleccunningham/marjoram.git
Cloning into marjoram...
Host key verification failed.

I have tried almost everything that has shown up in Google searches, and I am dumbfounded on why this will not work. Any ideas?

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

Also, I am not using anything like Jenkins.

另外,我没有使用像詹金斯这样的东西。

采纳答案by Devendra D. Chavan

Resolved the issue... you need to add the ssh public key to your github account.

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

  1. Verify that the ssh keys have been setup correctly.
    1. Run ssh-keygen
    2. Enter the password (keep the default path - ~/.ssh/id_rsa)
  2. Addthe public key (~/.ssh/id_rsa.pub) to github account
  3. Try git clone. It works!
  1. 验证 ssh 密钥是否已正确设置。
    1. ssh-keygen
    2. 输入密码(保持默认路径 - ~/.ssh/id_rsa
  2. 公钥 ( ~/.ssh/id_rsa.pub)添加到 github 账户
  3. 试试git clone。有用!


Initial status (public key not added to git hub account)


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

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


Now, add the public key ~/.ssh/id_rsa.pubto the github account (I used cat ~/.ssh/id_rsa.pub)


现在,将公钥添加~/.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 [email protected]: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)
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 [email protected]: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)

回答by Tupy

The issue could be that Github isn't present in your ~/.ssh/known_hosts file.

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

Append GitHub to the list of authorized hosts:

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

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

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

回答by Smart Coder

Well, from sourceTree I couldn't resolve this issue but I created sshkey from bash and at least it works from git-bash.

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

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

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

回答by shaosh

I had the same issue, and the solution is very simple, just change to git bash from cmd or other windows command line tools. Windows sometimes does not work well with git npm dependencies.

我遇到了同样的问题,解决方案很简单,只需从 cmd 或其他 Windows 命令行工具更改为 git bash 即可。Windows 有时不能很好地处理 git npm 依赖项。