Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install with git+ssh doesn't use existing ssh key for user

Tags:

git

github

npm

ssh

I want to reference a private GitHub repo in my project. I'm trying commands like:

npm i git+ssh://[email protected]/<myusername>/<myprivaterepo>.git

However it seems to not notice that I have SSH keys already configured on my (Windows 11) system. I can happily clone the repo, but executing the above command instead prompts me to sign in to GitHub:

GitHub Sign In

According to my searches online, this should work without additional authentication. For example, this article explains how to set this up - I can skip steps 2 and 3 as my SSH key already works (verified with ssh -T [email protected]), but I still get a prompt, and I don't want to add unnecessary additional access to my GitHub account where it isn't technically needed.

Does anyone know why I am getting this prompt?

like image 358
William Forty Avatar asked Apr 22 '26 16:04

William Forty


1 Answers

I figured this out myself - it's apparently a common issue in a variety of contexts, but in my search around npm related commands, I didn't find anywhere referencing this happening with npm, hence my question.

Thanks to this comment I stumbled upon, I discovered there's a setting for controlling handling credentials. You can check its value with git config credential.helper. I was blissfully ignorant that this existed as I normally use SSH key pairs from the command line.

I solved my issue by turning off the credential helper completely for git on my system, with:

git config --system --unset credential.helper

Note that this required administrative privileges to do, as the relevant config file lives in the Program Files directory (C:\Program Files\Git\etc\gitconfig).

like image 121
William Forty Avatar answered Apr 24 '26 05:04

William Forty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!