3

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?

2 Answers 2

6

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).

Sign up to request clarification or add additional context in comments.

1 Comment

After that, since I use Windows, I also had to run start-ssh-agent (and not ssh-agent) to get it to work. Source: stackoverflow.com/a/63173335/5905695
0

The reason is the git ssh private key is not stored on the jenkins host,you need use the private key from jenkins credential,with version 2.30+ git,git support use GIT_SSH_COMMAND to set private key,the code in jenkinsfile as bellow

 stage('install') {
                withCredentials([sshUserPrivateKey(credentialsId: "keyId", keyFileVariable: 'key')]) {
                // from git 2.30+,git support use GIT_SSH_COMMAND to set private key 
                sh 'GIT_SSH_COMMAND="ssh -i $key" npm install'
                }
     }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.