为什么 flutter pub 找不到我的 github ssh 密钥?

dir*_*kbo 4 git ssh github flutter

我的 flutter App 依赖于一个私有托管在 github 上的模块。
当我pub get从 Powershell运行时,我得到:

Git error. Command: `git clone --mirror ssh://git@github.com:dirkbo/repo-name.git C:\src\flutter\.pub-cache\git\cache\repo-name-123ba`
stdout:
stderr: Cloning into bare repository 'C:\src\flutter\.pub-cache\git\cache\repo-name-123ba'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
exit code: 128
Run Code Online (Sandbox Code Playgroud)

当我复制失败的命令并直接在同一个 powershell 中运行时:

git clone --mirror git@github.com:dirkbo/repo-name.git C:\src\flutter\.pub-cache\git\cache\repo-name-123ba
Run Code Online (Sandbox Code Playgroud)

一切正常:

Cloning into bare repository 'C:\src\flutter\.pub-cache\git\cache\repo-name-123ba'...
Enter passphrase for key '/c/Users/dirkb/.ssh/id_rsa':
remote: Enumerating objects: 229, done.
remote: Counting objects: 100% (229/229), done.
remote: Compressing objects: 100% (132/132), done.
remote: Total 229 (delta 13), reused 229 (delta 13), pack-reused 0
Receiving objects: 100% (229/229), 19.32 MiB | 1.45 MiB/s, done.
Resolving deltas: 100% (13/13), done.
Run Code Online (Sandbox Code Playgroud)

在我的pubspec.yaml尝试中:

repo:
    git: ssh://git@github.com/dirkbo/repo-name.git
Run Code Online (Sandbox Code Playgroud)

(结果见上)

repo:
    git: git@github.com:dirkbo/repo-name.git
Run Code Online (Sandbox Code Playgroud)

这给了我:

Git error. Command: `git fetch`
stdout:
stderr: git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
exit code: 128
Run Code Online (Sandbox Code Playgroud)

运行的批处理命令似乎pub get找不到我的 ssh 密钥。

dir*_*kbo 8

问题是 Windows 没有使用正确的 ssh 程序,而不是 openssh 使用它的内部 ssh 程序,这当然不知道我在 openssh 中的密钥。

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

所以在配置 git 以使用 OpenSSH 后,flutter pub get找到我的密钥,要求输入密码并正确拉取包。

感谢https://github.com/desktop/desktop/issues/5641#issuecomment-421801704