cargo: failed to authenticate when downloading repository
While going through the docs, this one hit me:
~/code/rust-projects/guessing_game master [!?] $ cargo build
Updating registry `https://github.com/rust-lang/crates.io-index`
error: failed to load source for a dependency on `rand`
Caused by:
Unable to update registry https://github.com/rust-lang/crates.io-index
Caused by:
failed to fetch `https://github.com/rust-lang/crates.io-index`
Caused by:
failed to authenticate when downloading repository
attempted ssh-agent authentication, but none of the usernames `git` succeeded
To learn more, run the command again with —verbose.
The reason I’m hitting this issue is buried in my gitconfig
[url "git@github.com:"]
insteadOf = https://github.com/
I am aware that this bug is a byproduct of how I have things set up locally, but since I’m capable of cloning https://github.com/rust-lang/crates.io-index without any issues with the above settings, I was hoping that I’d be able to use cargo in that way as well.
Thanks!
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 37
- Comments: 20 (1 by maintainers)
Links to this issue
Commits related to this issue
- fix(/users/common.nix): remove URL rewriting from git note: URL rewriting blocked `cargo-tarpaulin` from successfully installing and seems related to https://github.com/rust-lang/cargo/issues/3381. R... — committed to johnrichardrinehart/JohnOS by johnrichardrinehart 3 years ago
- fix(/users/common.nix): remove URL rewriting from git note: URL rewriting blocked `cargo-tarpaulin` from successfully installing and seems related to https://github.com/rust-lang/cargo/issues/3381. R... — committed to johnrichardrinehart/JohnOS by johnrichardrinehart 3 years ago
- Add Cargo global config Forces `cargo` to use the `git` executable for git operations. See this GitHub issue for context: https://github.com/rust-lang/cargo/issues/3381 — committed to kplattret/dotfiles by kplattret 2 years ago
- Add Cargo global config Forces `cargo` to use the `git` executable for git operations. See this GitHub issue for context: https://github.com/rust-lang/cargo/issues/3381 — committed to kplattret/dotfiles by kplattret 2 years ago
- [git][rust] added to gitconfig to compensate for cargo bug cargo install brakes if you've configured git to use ssh instead of http for github urls. explanation of the workaround here https://github... — committed to masukomi/masuconfigs by masukomi 2 years ago
Leave it here to help somebody… I had a similar issue with
ssh:dependency, but fixed it by starting ssh agent:I had the same setup in a global
~/.gitconfigThis is a somewhat common for few reasons. One is to deal with git submodules in a unified way: so you don’t need to handle
https::/vsgit@differently.Running
ssh-agentas @DenisKolodin suggested, didn’t work for me. The only way to workaround it was to remove this global config.Just in case, somebody will land here from google with the same errors (
https://github.com/rust-lang/crates.io-index), and above ☝️ approaches didn’t work, cause you have complicated auth to git from your machine, for example 🤷add to your cargo config.toml:
The following links from the docs saved my days: https://doc.rust-lang.org/cargo/appendix/git-authentication.html?highlight=auth#git-authentication https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
Workaround from https://github.com/rust-lang/cargo/issues/2078#issuecomment-434388584:
To apply globally, add this to
~/.cargo/config:For future travellers this is what I use:
I think part of your problem was that your
~/.gitconfighas the wrong replacement, as @DenisKolodin has mentioned, it is:Not:
With the @DenisKolodin replacement rule,
evalssh-agent -sandssh-add` work.it seems work after i comment
@HaoZeke it didn’t fix my issue even if I use
The problem appear when I set a dependencies and run
cargo build, so,after runssh-add,you shou runcargo buildto instead ofcargo ...export CARGO_NET_GIT_FETCH_WITH_CLI=true
Just leaving another thing that helped me after none of the other things worked - I had multiple SSH keys saved in rsa and ed25519 files named
id_rsa,id_ed25519along with their public files in the .ssh folder. By making .ssh use the ed25519 key explicitely, I was able to solve the problem. This is how my .ssh/config file looks like -Not a great experience for Rust newcomers… It took a while to find this seemingly hacky solution while following the documentation.
Lifesaver! phew
Mark
oh good point, I was not aware of this difference.
FWIW, there is some work happening in libgit2 that would allow to avoid all such problems all together https://github.com/libgit2/libgit2/pull/4667