无法在 WSL 中使用 git。 C:\Windows\System32\OpenSSH\ssh.exe: 未找到

问题描述 投票:0回答:3

我使用的是 Windows 10,不久前我决定使用 WSL,这样我就可以获得 zsh。但是,现在我不能再从 wsl 终端使用 git,即我不能再从远程仓库

git pull
。当我尝试时,我得到以下信息...

'C:\Windows\System32\OpenSSH\ssh.exe': 1: C:\Windows\System32\OpenSSH\ssh.exe: not found
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

此类操作在 bash 和

GitHub Desktop
中运行良好。为什么 WSL 尝试从 Windows 使用 OpenSSH(应该是 Linux,对吧?)

我正在努力寻找有关此问题的信息,因此非常感谢任何帮助。如果我可以提供更多信息,请告诉我。

windows git ssh windows-subsystem-for-linux
3个回答
13
投票

像这样更改值“core.sshCommand”后,我遇到了相同的错误:

git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"

在我的文件 ~/.gitconfig 中,我禁用了换行符,如下所示:

#[core]
#       sshCommand = 'C:\\Windows\\System32\\OpenSSH\\ssh.exe'

然后,当您在 git 存储库中时,如果您遇到同样的问题,请检查您的 my-project/.git/config 文件,如果有新配置,请按上述方式禁用它。

就我而言,它有效:-)
祝你有美好的一天


0
投票

仔细检查您是否有一个指向

GIT_SSH
的环境变量
C:\Windows\System32\OpenSSH\ssh.exe
:这在 WSL 会话中不是有效路径。

取消设置。
之后,这取决于使用的 Windows 10(1709?1809?20H1?...),以及使用的 WSL(WSL1 或 WSL2?)。


0
投票

正如ljr95response下的回复中提到的mmv_sat,通过将

core.sshCommand
的git配置从
C:\Windows\System32\OpenSSH\ssh.exe
更改为
'C:\Windows\System32\OpenSSH\ssh.exe'
,我解决了这个问题。

但是,我所做的一切都与在 WSL 中使用 git 无关;这都是为了我在 Windows 上的 PowerShell 中使用 git 和 ssh 来访问 Bitbucket。

我的错误

Cloning into 'repo_name'...
C:\windows\System32\OpenSSH\ssh.exe: line 1: C:windowsSystem32OpenSSHssh.exe: command not found
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

如果您收到像我一样的错误,以下解决方案可能会对您有所帮助。

查看您的配置值

您可以使用以下方式查看您自己的配置:

git config --list

对我来说,看起来像:

...
core.sshcommand=C:\windows\System32\OpenSSH\ssh.exe

分辨率

重新配置 git config

core.sshCommand
路径以单引号括起来。

我执行此操作的命令是:

git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"

然后我就能够按预期克隆我的存储库。

© www.soinside.com 2019 - 2024. All rights reserved.