git - 服务器主机密钥未缓存
我尝试将更改从本地存储库推送到远程存储库。当我输入:
git push origin
我收到以下错误:
The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
Connection abandoned.
fatal: The remote end hung up unexpectedly
我该如何解决这个问题?我在 Windows 7 中从命令行使用 git。
编辑
当我尝试执行简单的 ssh 时,
ssh user@hostname
出现以下错误:
Could not create directory '/c//%HOMEDRIVE%%HOMEPATH%/.ssh'.
percent_expand: unknown key %H
不知怎的,它不会创建目录,因为路径无效。如何解决这个问题?
@eckes:Edit2
我的主页设置为 %HOMEDRIVE%%HOMEPATH%
这是正确的吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(21)
对于那些通过标准命令提示符使用 PuTTY 在 Windows 上设置 MSYS Git 的人,将主机添加到 PuTTY 缓存的方法是运行
例如:
只需回答
y
,然后按 Ctrl+其余的C。不过,请检查指纹。这个警告是有充分理由的。一些 git 服务的指纹(请编辑以添加更多):
16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
97:8c:1b:f2:6f:14:6b: 5c:3b:ec:aa:46:46:74:7c:40
7e:af:8d:ec:f0:39:5e:ba:52:16:ce:19:fa:d4:b8:7d
For those of you who are setting up MSYS Git on Windows using PuTTY via the standard command prompt, the way to add a host to PuTTY's cache is to run
For example:
Just answer
y
, and then Ctrl+C the rest.Do check the fingerprint though. This warning is there for a good reason. Fingerprints for some git services (please edit to add more):
16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40
7e:af:8d:ec:f0:39:5e:ba:52:16:ce:19:fa:d4:b8:7d
尝试从 Git Bash 提示符中执行“set | grep -i ssh”
如果您的设置与我的类似,您可能已经设置了这些:
我做了一个
,然后它就工作了,..我猜 putty 将其密钥保存在其他地方作为 $HOME /.ssh 或其他...(我在 $HOME 设置为“C:\Users\usrnam”而不是“/C/Users/usrnam/”的盒子上也遇到了问题
,无论如何,您的里程可能会有所不同,但这对我来说解决了:-)
(可能只需要取消设置 GIT_SSH 就足够了,但我很高兴)
注意:如果取消设置对你不起作用,请尝试以下操作:
Try doing a "set | grep -i ssh" from the Git Bash prompt
If your setup is like mine you probably have these set:
I did a
and it worked after that,.. I guess putty saves its keys somewhere else as $HOME/.ssh or something... (I've also had a problem on a box where $HOME was set to "C:\Users\usrnam" instead of "/C/Users/usrnam/"
anyway, your mileage may vary, but that fixed it for me. :-)
(probably just doing the unset GIT_SSH is enough, but I was on a roll)
Note: if unset doesn't work for you, try this:
该消息意味着
origin
的主机密钥不存在于您的可信主机文件中。要解决此问题,请打开到
origin
的普通 SSH 连接,SSH 会询问您是否要信任远程主机(从 Git 控制台):如果您信任远程主机(即键入
yes
),SSH 会将其密钥添加到已知主机列表中。之后,您应该能够执行
git Push origin
。作为替代方案,您还可以手动将
origin
密钥添加到.ssh/known_hosts
中,但这要求您遵守known_hosts
的格式> 文件,如sshd
的手册页中所述( AUTHORIZED_KEYS 文件格式部分)。The message means that the host key of
origin
is not present in your trusted hosts file.To get around this, open a plain SSH connection to
origin
and SSH will ask you if you want to trust the remote host (from the Git console):If you trust the remote host (i.e. type
yes
), SSH will add its key to the list of known hosts.After that, you should be able to do your
git push origin
.As an alternative, you could also manually add the key of
origin
to.ssh/known_hosts
but this requires that you adhere to the format of theknown_hosts
file as described in the man page ofsshd
(Section AUTHORIZED_KEYS FILE FORMAT).我怀疑您的
GIT_SSH
环境变量设置为%ProgramFiles(x86)%\putty\plink.exe
。由于某些原因,PLink 不使用用户目录中的
.ssh/known_hosts
文件来存储远程主机密钥。如果这确实是您的情况,并且您想使用选美可能是故意的,则需要先使用 PLink 连接到主机。
您应该会收到类似的消息
一旦您回答了问题并成功连接到远程主机,您就应该准备就绪。继续并再次尝试推动。
I suspect that your
GIT_SSH
environment variable is set to%ProgramFiles(x86)%\putty\plink.exe
.For some reason, PLink does not use the
.ssh/known_hosts
file in your user directory to store the remote hosts keys.If this is actually your case, and it might be so on purpose if you want to use pageant, you need to use PLink to connect to the host first.
You should get a similar message
Once you have answered
y
to the question and successfully connected to the remote host, you should be all set. Go ahead and try your push again.仅通过 ssh 连接到主机是不够的,至少在 Windows 上是这样。这会将主机密钥添加到 ssh/known_hosts 中,但错误仍然存在。
您需要关闭 git bash 窗口并打开一个新窗口。然后注册表缓存被清除,推/拉操作即可开始工作。
Just ssh'ing to the host is not enough, on Windows at least. That adds the host key to
ssh/known_hosts
but the error still persists.You need to close the git bash window and open a new one. Then the registry cache is cleared and the push/pull then works.
如果您在使用 ATLASSIAN SOURCETREE 执行 git 推/拉操作时收到有关无法识别的主机密钥的消息,您将无法回答 y/n,并且推/拉操作将在不缓存密钥的情况下中止。但是,转到 SourceTree Tools->Options(常规选项卡)并将 SSH 客户端(在 SSH 客户端配置下)从 PuTTY 更改为 OpenSSH 将允许缓存密钥,而无需更改任何其他内容。
If you receive the message about the unrecognized host key while doing git push/pull operations using ATLASSIAN SOURCETREE you do not have the ability to answer y/n and the push/pull operation will be aborted without caching the key. However going to SourceTree Tools->Options (General Tab) and changing the SSH Client under (under SSH Client Configuration) from PuTTY to OpenSSH will allow the key to be cached without changing anything else.
Rene,您的
HOME
变量设置不正确。将其更改为c:\Users\(your-username)
或仅更改为%USERNAME%
。Rene, your
HOME
variable isn't set correctly. Either change it toc:\Users\(your-username)
or just to%USERNAME%
.使用 Plink 的解决方案
将 此 python 脚本 保存到
known_hosts.py
:在 Win7x64 和 Python 2.7 上测试。
然后运行:
并选择导入到注册表中。 keyscan 将检索域的公钥(我在使用 bitbucket 时遇到了问题),然后 python 脚本将其转换为 Plink 格式。
Solution with Plink
Save this python script to
known_hosts.py
:Tested on Win7x64 and Python 2.7.
Then run:
And choose to import into the registry. The keyscan will retrieve the public key for the domain (I had my problems with bitbucket), and then the python script will convert it to Plink format.
遇到同样的问题,并且忘记连接到实际存储库所在的端口上的 SSH,而不仅仅是一般的 SSH 端口,那么主机密钥就不同了!
Had the same issue, and forget to connect to SSH on port where is actuall repository, not just general SSH port, then the host key is different!
只需打开 Putty 并尝试与您想要推送代码的远程服务器建立连接。
当对话框出现时,按“是”(您信任远程),然后一切都会好起来。
Just open Putty and try to establish connection to remote server you want to push your code.
when the dialog appears press Yes(you trust remote) then everything would be OK.
工作环境:
第一:根据Regedit删除registy中的puttyknown_hosts。
然后:在Window的cmd中执行命令
%GIT_SSH% user@hostname
即可解决问题。希望对大家有所帮助。
Working environment:
First: Delete putty known_hosts in registy according to the Regedit.
Then: Executing the command
%GIT_SSH% user@hostname
in Window's cmd solves the problem.Hope it helps you all.
正如 Roman Starkov 的回答,
plink
需要将主机添加到其缓存中。对于使用 Git Extensions 的人:
替换为实际路径)
例如
注意:确保使用与 Git 扩展相同的 plink/klink!
As answered by Roman Starkov,
plink
needs to add the host to it's cache.For people using Git Extensions:
(replace with the actual paths)
e.g.
Note: Make sure to use the same plink/klink that Git Extensions is using!
当我尝试在 Windows 7 计算机上克隆存储库时,我也遇到了同样的问题。我尝试了这里提到的大部分答案。他们都不为我工作。
对我有用的是运行Pageant(Putty 身份验证代理)程序。一旦选美在后台运行,我就能够克隆、推送和复制。从存储库拉取/拉取到存储库。这对我有用,可能是因为我已经设置了我的公钥,以便每当第一次使用它时都需要密码&选美比赛开始。
I too had the same issue when I was trying to clone a repository on my Windows 7 machine. I tried most of the answers mentioned here. None of them worked for me.
What worked for me was, running the Pageant (Putty authentication agent) program. Once the Pageant was running in the background I was able to clone, push & pull from/to the repository. This worked for me, may be because I've setup my public key such that whenever it is used for the first time a password is required & the Pageant starts up.
从 PuTTY 更改为 OpenSSH 为我解决了这个问题,无需取消设置 GIT_SSH 等。
Changing from PuTTY to OpenSSH fixed this issue for me, without needing to unset GIT_SSH, etc.
我使用这个 解决方法。
您只需切换到嵌入式 Git,按下“是”按钮,然后切换回系统 Git。
您可以在以下位置找到此选项
I solved similar problem using this workaround.
You just have to switch to Embedded Git, push, press Yes button and then switch back to System Git.
You can find this option in
直接使用 Bash 添加主机并没有解决问题,在 Git 扩展中使用“Fetch all”时仍然出现错误。通过在一个分支上使用“拉取”,Git 扩展会通过 Bash 弹出屏幕自动添加所需的主机。完成此操作后,我可以再次使用“获取全部”。不确定 Git 扩展有何不同。
Adding the host directly with Bash didn't solve the issue, the error still occurred when using 'Fetch all' in Git Extensions. By using 'Pull' on one branch, the required host was added automatically by Git Extensions with a Bash pop-up screen. After doing this I was able to use 'Fetch All' again. Not sure what is done by Git Extensions differently.
我已经尝试了上述所有方法,但没有一个可以解决我的笔记本电脑上的相同问题。最后,我没有在 git bash 中将分支推送到原点,而是使用 TortoiseGit 的推送选项来进行推送,然后弹出一个窗口,要求我将新的主机密钥添加到缓存中,单击“是”按钮后,一切都会进行现在好了。
希望对大家有所帮助。
I have tried all the methods above but none of them could fix the same issue on my laptop. Finally instead of pushing the branch to origin in git bash, I trun to use TortoiseGit's push option to do the pushing, then a window pops-up to ask me to add the new host key to cache, after clicking the yes button, everything goes fine now.
Hope it helps to you all.
我换了硬盘,安装了Windows。当尝试上传文件时收到此命令窗口。
我按“y”,然后按 Ctrl + C。打开 putty.exe,添加一个旧密钥,然后返回到 git 并推送文件。
I changed a hard disk, installed Windows. When tried to upload files received this command window.
I pressed "y", then Ctrl + C. Opened
putty.exe
, added an old key ther returned to git and pushed files.在 Windows 7 或 10 中,对我有用的技巧是删除 GIT_SSH 系统变量。之前设置使用Plink,现在换成了Putty。这导致了 Plink.exe 错误
。由于 PC 是 64 位操作系统,因此还安装了旧的 Git(32 位版本)并更新到 Git(例如 Git-2.20.1-64-bit.exe)。
不管怎样,Putty/Plink 甚至没有被 Git 使用,因为在 Git 安装中它默认使用 Open SSH。
In Windows 7 or 10, the trick that worked for me is deleting the GIT_SSH system variable. It was set before to use Plink, and now was replaced by Putty. This was causing Plink.exe error
There was also an old installation of Git (32-bit version) and updating to Git(e.g. Git-2.20.1-64-bit.exe) since the PC was 64-bit OS.
Anyway the Putty/Plink was not even used by Git since in the Git installation it was default to use Open SSH.
我更改了 SSH 密钥,就发生了这种情况。
我尝试了一些解决方案,但失败了,放弃了。
最后,我选择 OpenSSH 而不是 PuTTY,然后就可以了:)
I changed my SSH key and this happend.
I tried some solution but it failed, and give up.
Finally, I select the OpenSSH instead of PuTTY, then it works :)
只需卸载 Git 扩展并通过选择 OpenSSH 而不是再次安装
Just uninstall Git Extensions and Install again by choosing OpenSSH instead of