【问题标题】:Why is flutter pub get not finding my ssh-key for github?为什么flutter pub找不到我的github ssh-key?
【发布时间】:2020-12-28 18:22:32
【问题描述】:

我的 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 密钥。

【问题讨论】:

  • 您可以尝试通过 pubspec 指定分支和依赖项名称吗?喜欢:dependencies: kittens: git: url: git@github.com:munificent/kittens.git ref: some-branch 你也可以试试ssh://git@github.com:munificent/kittens(删除.git)
  • 我已经尝试了你的两个建议,结果是一样的。似乎 pub get 在不同的 shell 中运行,我的 ssh-key 是未知的。
  • 您是在 Visual Studio Code 还是在 android Studio 中运行您的应用程序?还是别的什么?
  • 我在 AndroidStudio 和 Windows Powershell 中尝试过。
  • 这可能与路径问题有关? Powershell 使用 home 目录作为默认位置,而 AndroidStudio 来自项目文件夹。这可能会导致混淆,具体取决于您的 SSH 客户端和操作系统。我假设你在 Windows 上,对吧?

标签: git flutter github ssh


【解决方案1】:

问题是 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

【讨论】:

  • 谢谢你,你是真正的生命救星。
【解决方案2】:

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

dependencies:
  flutter:
    sdk: flutter

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

【讨论】:

  • 这是我尝试过但不起作用的方法之一。
【解决方案3】:

在我的情况下,我的存储库是公共的,并且包在子文件夹中。我通过包所在的子文件夹名称设置路径。

dependencies:
  flutter:
    sdk: flutter

  flutter_pi:
    git:
      url: git@github.com:{username}/flutter-packages.git
      path: flutter_pi
      ref: master

【讨论】:

    猜你喜欢
    • 2012-04-15
    • 2020-09-04
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    • 2012-07-27
    • 2019-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多