git - 使用 SSH 的 Git 克隆在 Windows 上不起作用 - 收到断开连接,无法从远程存储库读取
问题描述
我已经在新笔记本电脑上完成了 Git(版本 2.20.1.windows.1)的全新安装,但我无法克隆我的任何 Github 存储库。我也尝试过 Gitlab 并且遇到了同样的问题。
这是我尝试克隆 Github 调试存储库时遇到的错误:
$ git clone git@github.com:github/debug-repo debug-repo-ssh
Cloning into 'debug-repo-ssh'...
Received disconnect from 140.82.118.4 port 22:11: Bye Bye
Disconnected from 140.82.118.4 port 22
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
这是ssh -vT git@github.com
命令的输出:
$ ssh -vT git@github.com
OpenSSH_7.9p1, OpenSSL 1.1.1a 20 Nov 2018
debug1: Reading configuration data /c/Users/Tam/.ssh/config
debug1: /c/Users/Tam/.ssh/config line 1: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [140.82.118.4] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Tam/.ssh/id_github type 0
debug1: identity file /c/Users/Tam/.ssh/id_github-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
debug1: Remote protocol version 2.0, remote software version babeld-64adca0f
debug1: no match: babeld-64adca0f
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
Received disconnect from 140.82.118.4 port 22:11: Bye Bye
Disconnected from 140.82.118.4 port 22
它甚至没有到要我输入密码的地步。
解决方案
我无法弄清楚为什么 git 捆绑的 ssh 不能在我的笔记本电脑上运行,但我找到了一个稳定的解决方法。
- 从http://www.mls-software.com/opensshd.html安装了适用于 Windows 的 OpenSSH (OpenSSH_for_Windows_7.7p1) 。我刚刚发现它也可以通过Windows 10 创意者更新获得
安装并重新打开 PowerShell 后,runningssh -vT git@github.com
要求输入我的密码并成功验证我的身份,但git-agent
命令失败。这是一个错误,例如Could not connected to the authentication agent
- 要解决 ssh-agent 问题,我只需
OpenSSH Authentication Agent
要从 services.msc 启用服务。我将启动模式设置为自动(延迟启动)。
这让ssh-agent
,ssh-add
和ssh-add -l
命令正常工作,但 git 命令仍然失败,并出现与以前完全相同的错误。
- 为了解决 git 命令的最后一个问题,我将
SSH_GIT
环境变量设置为我安装 OpenSSH 的位置。对我来说就是C:\Windows\System32\OpenSSH\ssh.exe
。这是一个应该有所帮助的指南。
一旦我这样做并重新启动 PowerShell,git clone 和所有其他命令就开始工作了。
推荐阅读
- javascript - 如何在 ReactJs 的复选框中显示星期几
- protractor - 检查量角器黄瓜框架中是否存在元素
- c++ - 我有两组数据相互映射。有没有办法根据另一个变量的值检查相应变量的值?
- arrays - 如何在c中水平查找二维数组(10x2)中的重复值
- java - EditText 没有出现在模拟器中
- matomo - 当参数包含大写字母时,Matomo Track 事件不起作用
- php - 如何将txt文件中的内容获取到数组中
- firebase - 使用firebase在flutter中安排通知
- java - 如何在 intelliJ 中切换 java 版本?
- css - 如何使 React Material-UI Accordion 填充整个高度?