[英]Git clone using SSH not working on windows - Received disconnect, could not read from remote repository
I've done a fresh install of Git (version 2.20.1.windows.1) on a new laptop but I'm not able to clone any of my Github repositories.我已经在新笔记本电脑上完成了 Git(版本 2.20.1.windows.1)的全新安装,但我无法克隆任何 ZE1ADBCBB92C622D0B3E619F9D0730 存储库。 I've also tried Gitlab and am having the same issue.我也尝试过 Gitlab 并且遇到了同样的问题。
This is the error I get when I try to clone the Github debug repository:这是我尝试克隆 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.
Here is the output of the ssh -vT git@github.com
command:这是ssh -vT git@github.com
命令的 output :
$ 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
It doesn't even get to the point of asking me for my passphrase.它甚至没有到要我输入密码的地步。
I wasn't able to figure out why git's bundled ssh isn't working on my laptop, but I've found a stable workaround.我无法弄清楚为什么 git 捆绑的 ssh 不能在我的笔记本电脑上运行,但我找到了一个稳定的解决方法。
After installing and reopening PowerShell, running ssh -vT git@github.com
asked for my passphrase and authenticated me successfully, but the git-agent
command was failing.安装并重新打开 PowerShell 后,运行ssh -vT git@github.com
询问我的密码并成功验证了我,但git-agent
命令失败。 It was an error like Could not connected to the authentication agent
这是一个错误,例如Could not connected to the authentication agent
OpenSSH Authentication Agent
service from services.msc.要解决 ssh-agent 问题,我只需要从 services.msc 启用OpenSSH Authentication Agent
服务。 I set the launch mode to Automatic (delayed start).我将启动模式设置为自动(延迟启动)。 That got the ssh-agent
, ssh-add
and ssh-add -l
commands working, but git commands were still failing with exactly the same error as before.这使ssh-agent
、 ssh-add
和ssh-add -l
命令正常工作,但 git 命令仍然失败,并出现与以前完全相同的错误。
SSH_GIT
environment variable to the location where I installed OpenSSH.为了解决 git 命令的最后一个问题,我将SSH_GIT
环境变量设置为我安装 OpenSSH 的位置。 For me that is C:\Windows\System32\OpenSSH\ssh.exe
.对我来说是C:\Windows\System32\OpenSSH\ssh.exe
。 Here's a guide that should help.这是一个应该有所帮助的指南。Once I did that and restarted PowerShell, git clone and all the other commands started working.一旦我这样做并重新启动 PowerShell,git clone 和所有其他命令就开始工作了。
Tried all kinds of solutions I could find online, but none of them worked, except answer from lzag .尝试了我可以在网上找到的各种解决方案,但除了lzag 的回答外,它们都没有奏效。
For people too lazy to follow the link, just add对于懒得关注链接的人,只需添加
Host github.com
IdentityFile ~/.ssh/<your ssh key>
into C:\Program Files\Git\etc\ssh\ssh_config (if that's where you installed Git)进入 C:\Program Files\Git\etc\ssh\ssh_config (如果那是你安装 Git 的地方)
The answer by @Flyaway solved my problem. @Flyaway 的回答解决了我的问题。 It took me a long time to come to this.我花了很长时间才明白这一点。 I wonder how this happened.我想知道这是怎么发生的。 Github already accepted your key before you point it out. Github 在您指出之前已经接受了您的密钥。
and by the way, I didn't save this to git config, but ssh config instead, also worked.顺便说一句,我没有将其保存到 git 配置中,而是 ssh 配置也有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.