cargo: Crates.io index update failing due to conflict with ~/.gitconfig
EDIT: workaround solution at https://github.com/rust-lang/cargo/issues/8172#issuecomment-659066173. EDIT: more precise explanation of this bug at https://github.com/rust-lang/cargo/issues/8172#issuecomment-640973958.
While trying to install delta, I got this error:
cargo build --release
Updating crates.io index error: failed to get
ansi_coloursas a dependency of packagegit-delta v0.1.1 (/home/marcospb19/delta)Caused by: failed to fetchhttps://github.com/rust-lang/crates.io-indexCaused by: failed to authenticate when downloading repository attempted ssh-agent authentication, but none of the usernames
gitsucceededCaused by: error authenticating: no auth sock variable; class=Ssh (23) make: *** [Makefile:2: build] Error 101
I know almost nothing about Rust or Cargo, sorry if this issue isn’t very clear.
Why would cargo use ssh to make this update?
Notes
Cargo and Rust --version:
1.43.0
OS: Arch Linux
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 22 (8 by maintainers)
If you want to have a global git configuration that tells git to always use SSH, then there isn’t any choice. All tools using git will use that configuration.
I think, if for whatever reason you really need to use https for Cargo’s index, I think an alternate solution would be to use this in gitconfig:
I’m not 100% certain that always works, but I did a quick test and it seems ok.
@marcospb19 I have a similar setup, for the same reason, but using
pushInsteadOfinstead; that way, things that clone/pull from github will not use SSH, but trying to push to github (which cargo never does) will use SSH.Here’s the configuration you want:
That should solve your problem.
@ehuss’s fix works great for me. I agree with @rjhornsby that at the very least a better message should be printed about the use of
insteadOfin gitconfig.Perhaps adding a section on it to The Cargo Book and linking to it, along with the
net.git-fetch-with-clilink, since the actual ‘Caused by’ was different. Maybe say “Possible causes: …” instead of caused by?Ah, sorry about the confusion. Cargo needs to communicate with GitHub for the index, and the
insteadOfgit configuration is telling Cargo to use SSH for that purpose. However, Cargo’s SSH behavior doesn’t exactly match that of thegitcommand-line client (it typically needs ssh-agent to be running). Thenet.git-fetch-with-cliCargo configuration value tells Cargo to use thegitcommand-line client for git interaction instead of its built-in git library. You can set that up by creating a file called~/.cargo/configand add the text:Assuming the
gitCLI is able to communicate with GitHub over SSH, then this should work.