为什么flutter pub无法找到我的github的ssh-key?

问题描述

我的flutter应用程序依赖于私人托管在github上的模块。
当我从Powershell运行pub get时,我得到:

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

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

git clone --mirror git@github.com:dirkbo/repo-name.git C:\src\flutter\.pub-cache\git\cache\repo-name-123ba

一切正常:

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.

在我的pubspec.yaml中,我尝试过:

repo:
    git: ssh://git@github.com/dirkbo/repo-name.git

(结果请参见上文)

repo:
    git: git@github.com:dirkbo/repo-name.git

这给了我

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

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

解决方法

问题是Windows没有使用正确的ssh程序,而是使用了内部的ssh程序而不是openssh,它当然不知道我在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

,

前段时间遇到相同的问题,只需将pubspec.yaml修复为:

dependencies:
  flutter:
    sdk: flutter

  flutter_ui_kit_poc:
    git:
      url: git@github.com:xxxxxx/flutter_ui_kit_poc.git
      ref: master

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...