Problem using ssh urls for external crates with Cargo on Windows


#1

Hi,

I have a crate which uses another crate placed on the private git repository on BitBucket. I use ssh-url in Cargo.toml. When I try to build a crate (with cargo build for instance) on Linux, everything works fine. But whenever I try to build it on Windows, it fails. The ssh keys are configured properly and I can pull external private repositories using git clone, but when it comes to cargo build it fails.

I tried to exectue a build from “Git Bash” (as it has ssh-agent.exe and ssh-add.exe) and I checked that ssh-add.exe -l contains the proper key. I also tried to use “Rust Shell” (MSVC Shell and GNU Shell) to issue cargo build. It always fails with an error:

Caused by:
  failed to fetch into C:\Users\Daniel\.cargo\git\db\rust_utils-ce5321d34a8b1546

Caused by:
  failed to authenticate when downloading repository
attempted ssh-agent authentication, but none of the usernames `git` succeeded

Caused by:
  [23/-1] error authenticating: failed connecting agent

Has anyone had this issue? Could you suggest me something to fix the problem. I don’t know whether it is a cargo bug or if any additional configuration required.

UPD. I found a workaround/hack, it does not solve the problem and requires having Linux machine, but it may help you to build a project when it’s critical for you as it were for me. So basically what I did: I configured rustup to use windows toolchain (mingw-64) and used crosscompilation to build a windows executable from my Linux machine (on Linux it works fine). Then I just executed cargo build --target=x86_64-pc-windows-gnu on my Linux machine and it built the windows executable successfully.


#2

I have the same problem on Windows 10 with Cygwin64 and Rust GNU ABI. I tried 3 variants for ssh URL and got following errors:

  1. Raw URL given by GitHub generates: invalid url git@github.com:Thierry61/my_routing.git: relative URL without a base

  2. Prefixing URL with “ssh://” generates: invalid url ssh://git@github.com:Thierry61/my_routing.git: invalid port number

  3. Replacing ‘:’ before username with ‘/’ generates: Unable to update ssh://git@github.com/Thierry61/my_routing.git
    Caused by:
    failed to fetch into C:\cygwin64\home\Thierry.cargo\git\db\my_routing-e273bad0a15cbb94
    Caused by:
    failed to authenticate when downloading repository
    attempted ssh-agent authentication, but none of the usernames git succeeded
    Caused by:
    [23/-1] error authenticating: failed connecting agent

The third URL syntax seems to be the right one, but cargo fails to connect to ssh agent, even though it is running properly (in the same Cygwin64 terminal, command “git clone ssh://git@github.com/Thierry61/my_routing.git” downloads correctly my_routing crate)


#4

Hi @Thierry61, I guess my problem is the same thing as the 3rd variant in your list. I get exactly the same error. I do not have cygwin installed, but I have Git Bash which contains ssh-agent and other utilities and it fails with the same error. I also tried to use both “Rust GNU Shell” and “Rust MSVC Shell” and it fails there as well.


#5

To use private repos on Windows, use Pageant as your SSH agent. The windows-msvc version of libssh2 doesn’t support UNIX sockets (duh), which is normally used on UNIX to talk to an SSH agent. On Windows, Pageant is also supported.


#6

Hi @jethrogb, I tried to use it, it was one of the things I tried, but at that time it did no solve the problem, because cargo crashed with a segfault. I have not checked the current state of cargo, it could be that the problem has been fixed since then.


#7

Ah, that might be https://github.com/libssh2/libssh2/issues/162, which has been fixed in latest nightly.


#8

Ok it still didn’t work with newer cargo due to https://github.com/alexcrichton/git2-rs/issues/202. I can confirm that the cargo version that comes with nightly-2016-10-03 is not affected by this bug or the bug I linked in my previous post.