What should I do when asked for a private key loaction when adding a private repository on windows

When trying to add my private repository using the julia repl. It sops adding with a line saying Private key location for 'git@github.com' [C:\Users\[username]\.ssh\id_rsa]:

I’m not entirely sure what I should type in as it’s already pointing to the private key loaction. I’ve tried the following.

  • Retyping in the private key location.
  • Typing in the public key location.
  • Typing in the directory tha contains both.
    But one of the above have allowed me to add my repository.

A few extra notes:

  • The ssh key was given to github.
  • The ssh key has been added to the agent.
  • This is done on gitbash.
  • I have looked at this thread but couldn’t find a solution.
  • The error I’m getting is ERROR: failed to clone from git@github.com:[private repo].git, error: GitError(Code:ERROR, Class:SSH, Failed to authenticate SSH session: Unable to open public key file)
1 Like

I have been struggling with this issue for a long time. It still causes me a lot of pain.

On linux at least, it seems that the core problem is that only the command line ssh uses .ssh/config, libgit2 does not use it in any way. I’m still not entirely sure why it won’t accept the key when I explicitly give it the location, but it seems like a moot point since one can’t do that in an automated fashion without some kind of config.

The only solution I am aware of is ssh-agent. That does work, but it is quite a pain to set up (if I had to do it again right now, I’d start by doing lots of duckduckgo searches).

I really wish there were some better solution, but at this point I don’t even know what that would be.

I’m afraid I have no idea what the situation is on Windows, but I’d imagine you’d still need to use ssh-agent or some Windows ssh-agent alternative.

1 Like

The situation gets much worse when you have multiple, interdependent private repositories. I’ve just given up and enter my credentials several times for every update.

2 Likes

My solution has been to manage repos with command line git and use ]dev.

It works ok at first, but of course you can’t version control your packages. At some point I started writing increasingly elaborate Julia scripts to pull all my repos.

I feel like eventually I will just have wound up completely re-writing Pkg.jl with command line git as a back-end just to circumvent this issue.

1 Like

Yeah, I used to recommend that. We started having problems with users accidentally committing Project.toml and Manifest.toml files with local paths still in them. Since I’m too lazy to figure out how to maintain a private registry, it’s also verbose to replace the local path with the remote.

1 Like

Could you test with Julia 1.3-RC2 and see if it makes a difference? https://github.com/JuliaLang/julia/pull/33089 might make a difference.

1 Like

Hi, thank you both for your help.

@ExpandingMan
I’ve been using an ssh-agent.
I reactivated just in case it by running $ eval $(ssh-agent) and ssh-add "C:\Users\[Username]\.ssh\id_rsa".
This hasn’t done anything, it’s behaving the same way.
You did mention having to perform many searches though, so were you thinking of using it another way?

@oatlzzvztd

The situation gets much worse when you have multiple, interdependent private repositories. I’ve just given up and enter my credentials several times for every update.

This is exactly this situation I’m in!

@GunnarFarneback
Unfortunatley that doesn’t seem to have fixed this.

FYI the error I’m getting is ERROR: failed to clone from git@github.com:[private repo].git, error: GitError(Code:ERROR, Class:SSH, Failed to authenticate SSH session: Unable to open public key file)

I’m going to added it to top post.

I wish I could be more helpful, it’s been a while since I’ve tried to set it up. I remember it being a pain, but basically working as advertised. One of my major concerns with it was it screwing up my existing, perfectly cogent .ssh/config usage for other things. Nervousness over that has probably been my main motivation for not pursuing it further. I think @oxinabox was the one who told me he uses ssh-agent, maybe he can chime in.

Exactly the same behavior.

1 Like

I have no memory of how i set my SSH-Agent up.
I just know I did, and that it works now.

3 Likes

For what it’s worth the arch linux wiki entries for these things are always extremely informative, but in this particular case it doesn’t clear up any of my biggest concerns about how my normal ssh config will be affected.

1 Like

I use both so i think it is fine

1 Like

For Windows, there is a very simple solution:

git config --global credential.helper manager

and then use https git URLs for everything.

Here is the slightly more elaborate explanation :slight_smile:

When you install standard git for windows, it also installs the git credential manager for Windows. That credential manager essentially “just works” for things like github etc. with private repos. It supports two factor authentication and all the other good things.

When you run git command line, it will look in all the normal git config locations for a configuration setting for the credential helper (system, global and user, or whatever they are). BUT NONE of them have the config setting for the credential manager, because there is yet another setting beyond system, global and user that only applies to the git command line, and that is where the credential helper is configured to use manager.

Julia and libgit2 look in the system, global and user configuration for credential helper settings, but not in this custom location for the git command line. And so by default, julia will not pick up the manager setting for the credential helper, and so you won’t get the “good” credential helper where everything just works.

The command line I posted above configures the global credential.helper setting to use manager. That setting is picked up by the julia package manager, and then everything just works.

At least on my system :slight_smile:

3 Likes

Thanks, but I’m getting this error when I try downloading private repositories.

Value cannot be null.
Parameter name: Username
Parameter name: operationArguments
fatal: ArgumentException encountered.

I don’t remember how someone figured this out, but for users to interact with our internal package registry they need to run ssh-add ~/.ssh/id_rsa from the shell prompt within julia (after uploading their public key to GitLab).

4 Likes

I am still struggling with getting this to work on Windows 10 after trying lots of things. Among them adding the Environmental Variables for private and public key path and running ssh-add from within the julia shell prompt. Using https paths is quite annoying as it would change my setup on all computers/servers…

Is there a clean solution somewhere? Or a suggestion of where to look for errors in my setup?

I created a new ssh-key and it works. For some reason Julia did not accept the key, while git/powershell did…

Thanks, but I’m getting this error when I try downloading private repositories.

Value cannot be null.
Parameter name: Username
Parameter name: operationArguments
fatal: ArgumentException encountered.

Yes, I’m also getting these, but they actually don’t seem to be fatal, everything then works just fine, so I just ignore those messages.

This worked for me:

5 Likes

This is my workaround in Windows 10: https://discourse.julialang.org/t/help-pkg-add-from-companys-bitbucket-repository-fails-due-to-ssh-authentication/33897/3?u=zhong_pan

1 Like

Thank you very much Sam, this works.