git - 未缓存服务器主机密钥

Ren*_*gen 100 windows git ssh putty plink

我尝试将更改从我的本地仓库推送到远程仓库.当我输入:

git push origin
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

我怎么解决这个问题?我在Windows 7中使用命令行中的git.

编辑

当我尝试做一个简单的ssh

ssh user@hostname
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Could not create directory '/c//%HOMEDRIVE%%HOMEPATH%/.ssh'.
percent_expand: unknown key %H
Run Code Online (Sandbox Code Playgroud)

不知何故,它不会创建目录,因为路径无效.如何解决这个问题?

@eckes:Edit2

我的家设置%HOMEDRIVE%%HOMEPATH%为这是正确的吗?

Rom*_*kov 154

对于那些通过标准命令提示符在Windows上使用PuTTY设置MSYS Git的人来说,将主机添加到PuTTY缓存的方法是运行

> plink.exe <host>
Run Code Online (Sandbox Code Playgroud)

例如:

> plink.exe codebasehq.com

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 2e:db:b6:22:f7:bd:48:f6:da:72:bf:59:d7:75:d7:4e
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n)
Run Code Online (Sandbox Code Playgroud)

只需回答y,然后按Ctrl + C休息.

尽管检查指纹.这个警告是有充分理由的.一些git服务的指纹(请编辑添加更多):

  • 这应该是公认的答案.这正是错误消息所指的内容.在我克隆的情况下,我使用了FQDN,但在我的新机器上,我只使用短的本地域名登录.我必须通过putty或plink作为FQDN登录,以缓存源上主机名的密钥.使用"git remote -v"可以帮助交叉检查用作远程的主机名. (15认同)
  • 它还可以将交互式PuTTY用于您尝试使用的主机.例如,如果您尝试在新的Windows计算机上首次克隆Github存储库,请使用PuTTY打开与主机'github.com'的会话,接受有关服务器信任的提示,然后在命令行应该工作. (3认同)
  • 我最后通过将我的密钥添加到Pageant并直接使用Putty访问主机来解决这个问题.这会要求您将主机添加到缓存中.做同样的事情. (2认同)
  • 如果您的 git 存储库在自定义 SSH 端口上提供服务,请使用“-P”选择端口,例如:“plink.exe example.com -P 2222”。我可以从 github 克隆,但不能从我的个人服务器克隆,这让我很困惑。 (2认同)

小智 78

尝试从Git Bash提示符执行"set | grep -i ssh"

如果你的设置与我的一样,你可能有以下设置:

GIT_SSH='C:\Program Files (x86)\PuTTY\plink.exe'
PLINK_PROTOCOL=ssh
SVN_SSH='"C:\\Program Files (x86)\\PuTTY\\plink.exe"'
Run Code Online (Sandbox Code Playgroud)

我做了一个

unset GIT_SSH
unset PLINK_PROTOCOL
unset GIT_SVN
Run Code Online (Sandbox Code Playgroud)

之后它就起作用了..我猜putty将其键保存在其他地方作为$ HOME/.ssh或其他东西......(我在$ HOME设置为"C:\ Users \"的盒子上也遇到了问题usrnam"而不是"/ C/Users/usrnam /"

无论如何,你的里程可能会有所不同,但这对我来说是固定的.:-)

(可能只是做了未设置的GIT_SSH就足够了,但我还在滚动)

注意:如果未设置对您不起作用,请尝试以下操作:

set GIT_SSH=
Run Code Online (Sandbox Code Playgroud)

  • 未设置GIT_SSH也为我工作.谢谢! (3认同)
  • 安装git时,您可以选择不设置这些变量.它甚至是默认变体.虽然我也选择了plink集成,但这就是我在这里的原因)谢谢. (2认同)
  • "unset GIT_SSH"也适用于我,虽然我每次启动git bash时都必须这样做,这很无聊.关于如何自动化的想法? (2认同)

eck*_*kes 53

该消息表示主机密钥origin不存在于您的可信主机文件中.

要解决此问题,请打开一个普通的SSH连接origin,SSH将询问您是否要信任远程主机(来自Git控制台):

$ ssh 127.0.0.1
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
RSA key fingerprint is <FINGERPRINT>.
Are you sure you want to continue connecting (yes/no)?
Run Code Online (Sandbox Code Playgroud)

如果您信任远程主机(即类型yes),SSH会将其密钥添加到已知主机列表中.

在那之后,你应该能够做到git push origin.

作为替代方案,你也可以手动添加的关键origin.ssh/known_hosts,但是这需要你坚持的格式known_hosts文件中的手册页中所述sshd(第AUTHORIZED_KEYS文件格式).

  • 我在向github推送时得到了相同的消息,但是我可以ssh到github,我在`known_hosts`文件中有github.com. (4认同)
  • 您可以在Windows上使用PuTTY用于相同的目的,代替命令行SSH客户端. (2认同)

小智 19

我怀疑你的GIT_SSH环境变量设置为%ProgramFiles(x86)%\putty\plink.exe.出于某种原因,PLink不会使用.ssh/known_hosts用户目录中的文件来存储远程主机密钥.

如果这实际上是你的情况,如果你想使用选美,它可能是故意的,你需要首先使用PLink连接到主机.

"$GIT_SSH" user@hostname
Run Code Online (Sandbox Code Playgroud)

你应该收到类似的消息

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 86:7b:1b:12:85:35:8a:b7:98:b6:d2:97:5e:96:58:1d
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n)
Run Code Online (Sandbox Code Playgroud)

一旦您回答y了问题并成功连接到远程主机,就应该全部设置好.继续尝试再次尝试.