Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to authenticate when downloading repository #3381

Closed
jefflembeck opened this issue Dec 10, 2016 · 20 comments
Closed

failed to authenticate when downloading repository #3381

jefflembeck opened this issue Dec 10, 2016 · 20 comments

Comments

@jefflembeck
Copy link

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!

@alexcrichton
Copy link
Member

I believe this is a duplicate of #2078, but thanks for the report!

@therustmonk
Copy link

therustmonk commented Jun 14, 2017

Leave it here to help somebody...
I had a similar issue with ssh: dependency, but fixed it by starting ssh agent:

eval `ssh-agent -s`
ssh-add
cargo build

@vors
Copy link

vors commented May 27, 2018

I had the same setup in a global ~/.gitconfig

[url "ssh://git@github.com/"]
	insteadOf = https://github.com/

This 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::/ vs git@ differently.

Running ssh-agent as @deniskolodin suggested, didn't work for me. The only way to workaround it was to remove this global config.

@HaoZeke
Copy link

HaoZeke commented Oct 16, 2018

I had the same setup in a global ~/.gitconfig

[url "ssh://git@github.com/"]
	insteadOf = https://github.com/

This 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::/ vs git@ differently.

Running ssh-agent as @deniskolodin suggested, didn't work for me. The only way to workaround it was to remove this global config.

I think part of your problem was that your ~/.gitconfig has the wrong replacement, as @deniskolodin has mentioned, it is:

[url "git@github.com:"]
  insteadOf = https://github.com/

Not:

[url "ssh://git@github.com/"]
	insteadOf = https://github.com/

With the @deniskolodin replacement rule, eval ssh-agent -sandssh-add` work.

@vors
Copy link

vors commented Oct 17, 2018

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 libgit2/libgit2#4667

@lunny
Copy link

lunny commented Jun 15, 2019

@HaoZeke it didn't fix my issue even if I use

[url "git@github.com:"]
        insteadOf = https://github.com/

@tlightsky
Copy link

tlightsky commented Jan 20, 2020

it seems work after i comment

[url "git@github.com:"]
        insteadOf = https://github.com/

@dmitrybirin
Copy link

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:

[net]
git-fetch-with-cli = true

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

@asciifaceman
Copy link

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:

[net]
git-fetch-with-cli = true

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

Life saver. https git has always caused issues so I've always forced ssh auth

@cyphbt
Copy link

cyphbt commented Jul 3, 2021

Leave it here to help somebody...
I had a similar issue with ssh: dependency, but fixed it by starting ssh agent:

eval `ssh-agent -s`
ssh-add
cargo ...

The problem appear when I set a dependencies and run cargo build, so,after run ssh-add,you shou run cargo build to instead of cargo ...

@zhaohuxing
Copy link

Leave it here to help somebody...
I had a similar issue with ssh: dependency, but fixed it by starting ssh agent:

eval `ssh-agent -s`
ssh-add
cargo ...

Mark

@YodaEmbedding
Copy link

YodaEmbedding commented Nov 2, 2021

Workaround from #2078 (comment):

To apply globally, add this to ~/.cargo/config:

[net]
git-fetch-with-cli = true

johnrichardrinehart added a commit to johnrichardrinehart/JohnOS that referenced this issue Nov 10, 2021
note: URL rewriting blocked `cargo-tarpaulin` from successfully
installing and seems related to
rust-lang/cargo#3381. Removing this line
from git's config seemed to fix the problem.
johnrichardrinehart added a commit to johnrichardrinehart/JohnOS that referenced this issue Nov 10, 2021
note: URL rewriting blocked `cargo-tarpaulin` from successfully
installing and seems related to
rust-lang/cargo#3381. Removing this line
from git's config seemed to fix the problem.
@IloveKanade
Copy link

[net]
git-fetch-with-cli = true

Wow, It's worked!!!!

kplattret added a commit to kplattret/dotfiles that referenced this issue May 31, 2022
Forces `cargo` to use the `git` executable for git operations. See this
GitHub issue for context: rust-lang/cargo#3381
kplattret added a commit to kplattret/dotfiles that referenced this issue May 31, 2022
Forces `cargo` to use the `git` executable for git operations. See this
GitHub issue for context: rust-lang/cargo#3381
@Integralist
Copy link

For future travellers this is what I use:

# force authentication to use SSH rather than HTTPS.
# be aware this affects everything that tries to use git.
# for example, vim (and other tools) will try to clone plugins using SSH.
#
# git config --global --add url."git@github.com:".insteadOf "https://github.com/"
[url "git@github.com:"]
  insteadOf = https://github.com/

# avoid issues where the cargo-edit tool tries to clone from a repo you do not have WRITE access to.
# we already use SSH for every github repo, and so this puts the clone back to using HTTPS.
[url "https://github.com/rust-lang/crates.io-index"]
  insteadOf = https://github.com/rust-lang/crates.io-index

# avoid issues where the `cargo audit` command tries to clone from a repo you do not have WRITE access to.
# we already use SSH for every github repo, and so this puts the clone back to using HTTPS.
[url "https://github.com/RustSec/advisory-db"]
  insteadOf = https://github.com/RustSec/advisory-db

masukomi added a commit to masukomi/masuconfigs that referenced this issue Aug 12, 2022
cargo install brakes if you've configured git to use ssh instead of http
for github urls.

explanation of the workaround here
rust-lang/cargo#3381 (comment)
@krishna15898
Copy link

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_ed25519 along 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 -

Host github.com
 HostName github.com
 IdentityFile ~/.ssh/id_ed25519

@rizalgowandy
Copy link

export CARGO_NET_GIT_FETCH_WITH_CLI=true

@edjchapman
Copy link

Not a great experience for Rust newcomers... It took a while to find this seemingly hacky solution while following the documentation.

@chenzhuofu
Copy link

Workaround from #2078 (comment):

To apply globally, add this to ~/.cargo/config:

[net]
git-fetch-with-cli = true

Life saver!

@zigang93
Copy link

zigang93 commented May 6, 2023

Workaround from #2078 (comment):

To apply globally, add this to ~/.cargo/config:

[net]
git-fetch-with-cli = true

it doen't work for some cargo packages.. such as cargo-audit

cargo audit will failed with ssh error

@tolu0x
Copy link

tolu0x commented Jan 24, 2024

Leave it here to help somebody... I had a similar issue with ssh: dependency, but fixed it by starting ssh agent:

eval `ssh-agent -s`
ssh-add
cargo build

Lifesaver! phew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests