My flutter App depends on a module privately hosted on github.
When I run pub get
from Powershell, i get:
Git error. Command: `git clone --mirror ssh://[email protected]: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'...
[email protected]: 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
When I copy the failed command and run directly in the same powershell:
git clone --mirror [email protected]:dirkbo/repo-name.git C:\src\flutter\.pub-cache\git\cache\repo-name-123ba
Everything works fine:
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.
In my pubspec.yaml
I tried:
repo:
git: ssh://[email protected]/dirkbo/repo-name.git
(result see above)
and
repo:
git: [email protected]:dirkbo/repo-name.git
which gives me:
Git error. Command: `git fetch`
stdout:
stderr: [email protected]: 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
It seems like the batch command running pub get
can't find my ssh key.
Login to github.com and bring up your account settings by clicking the tools icon. Select SSH Keys from the side menu, then click the Add SSH key button. Name your key something whatever you like, and paste the contents of your clipboard into the Key text box. Finally, hit Add key to save.
The problem was that Windows did't use the correct ssh programm and instead of openssh was using it's internal ssh program, which of course didn't know about my keys in openssh.
git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"
So after configuring git to use OpenSSH, flutter pub get
finds my keys, asks for a password and pulls the package correctly.
Thanks to https://github.com/desktop/desktop/issues/5641#issuecomment-421801704
In my case, my repository is public & the package in the subfolder. I set the path by the subfolder name where package located.
dependencies:
flutter:
sdk: flutter
flutter_pi:
git:
url: [email protected]:{username}/flutter-packages.git
path: flutter_pi
ref: master
In my case, flutter pub get
was running well, but flutter pub upgrade
was erroring with
Permission denied (publickey)
The answer provided by @dirkbo solved only part of the problem for me, since there still was a conflict in my system between C:\Windows\System32\OpenSSH\ssh.exe
from Windows and usr\bin\ssh.exe
from Git Bash. Here I'm picking OpenSSH to handle all the operations:
Set-Service ssh-agent -StartupType Manual
ssh-agent
ssh-add -L
ssh-add
, inserting their respective password when prompted:ssh-add C:\Users\%YOUR_USER%\.ssh\id_github_home
ssh-add C:\Users\%YOUR_USER%\.ssh\id_github_work
git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"
Then I could get to run flutter pub upgrade
normally!
I think this already solves the problem, but I've also added an environment variable named GIT_SSH
:
set GIT_SSH=C:\Windows\System32\OpenSSH\ssh.exe
Note that every time start your computer, you need to run step 2 before running flutter pub upgrade
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With