git 我从 .ssh 文件夹中删除了 known_hosts 文件,但无法拉入或推送 BitBucket 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15535486/
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:47:36  来源:igfitidea点击:

I deleted the known_hosts file from .ssh folder and I can't pull or push in BitBucket repositories

gitsshkeybitbucket

提问by xpto

I made a mistake and deleted the "known_hosts" file in ".ssh" folder! Now I can't pull or push in BitBucket repositories.

我犯了一个错误并删除了“.ssh”文件夹中的“known_hosts”文件!现在我无法拉入或推送 BitBucket 存储库。

How can I solve it?

我该如何解决?

回答by Tuxdude

Try executing:

尝试执行:

ssh -T [email protected]

It would give you a message somethign like:

它会给你一条消息,比如:

The authenticity of host 'bitbucket.org (207.223.240.181)' can't be established.
RSA key fingerprint is 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40.
Are you sure you want to continue connecting (yes/no)? yes

Say yesafter verifying the host fingerprint (see details in the end).

yes验证主机指纹后再说(详情见文末)。

Then you should get this warning, which you can ignore safely:

然后你应该得到这个警告,你可以安全地忽略它:

Warning: Permanently added 'bitbucket.org,207.223.240.181' (RSA) to the list of known hosts.
conq: logged in as tuxdude.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

Try running the git pullor git pushonce again and it should work this time.

尝试再次运行git pullor git push,这次应该可以工作了。

NOTE: I assume you still have your .ssh/id_rsafile safely which is your private key for SSH authentication.

注意:我假设您仍然.ssh/id_rsa安全地拥有您的文件,这是您用于 SSH 身份验证的私钥。

Verifying Host Fingerprint

验证主机指纹

As @Pascal_dher pointed out, you can be a victim of man-in-the-middle attack if you do not verify the host's fingerprint (using some out of band approach that you can rely on). For bitbucket, the info is available here.

正如@Pascal_dher 指出的那样,如果您不验证主机的指纹(使用一些您可以依赖的带外方法),您可能会成为中间人攻击的受害者。对于 bitbucket,信息可在此处获得

回答by VonC

From the "using ssh with BitBucket" page, the next use of ssh should re-create that known_hostsfile:

“在 BitBucket 中使用 ssh”页面,下次使用 ssh 应重新创建该known_hosts文件:

Bitbucket hosts only allow Git and Mercurial to make SSH connections.
The first time you access Bitbucket using the SSH URL, your SSH client checks to see if the Bitbucket host is a known host. If the host is not in your ~/.ssh/known_hostsfile SSH warns you that it is adding the Bitbucket host to known hosts:

Bitbucket 主机只允许 Git 和 Mercurial 建立 SSH 连接。
首次使用 SSH URL 访问 Bitbucket 时,您的 SSH 客户端会检查 Bitbucket 主机是否为已知主机。如果主机不在您的~/.ssh/known_hosts文件中,SSH 会警告您它正在​​将 Bitbucket 主机添加到已知主机:

$ hg clone ssh://[email protected]/newuserme/mquotefork testkey
The authenticity of host 'bitbucket.org (207.223.240.182)' can't be established.
RSA key fingerprint is 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40.
Are you sure you want to continue connecting (yes/no)? 

If you view the contents of known hosts is stored you find the actual key is stored in a base64 encoded format:

如果您查看存储已知主机的内容,您会发现实际密钥以 base64 编码格式存储:

bitbucket.org,207.223.240.182 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw==

So simply using an ssh address (or just ssh command) should be enough to trigger that message again.

因此,只需使用 ssh 地址(或仅使用 ssh 命令)就足以再次触发该消息。