简体   繁体   English

由于私有git存储库ssh和https连接,npm安装失败

[英]npm install fails due to private git repository both ssh and https connections

I have the following package.json file and I am trying to run npm install, but it fails. 我有以下package.json文件,我正在尝试运行npm install,但它失败了。

    "test": "git+https://<TOKEN>@github.build.test.com/test.git",

I have ssh key matched to github. 我有与github匹配的ssh密钥。 However even I write the following, it always run with https. 但是,即使我写下以下内容,它也始终使用https运行。

    "test": "git+ssh://git@github.build.test.com/test.git",

In both case, I encounter following error message 在这两种情况下,我都会遇到以下错误消息

npm ERR! Error while executing:
npm ERR! C:\Program Files\Git\cmd\git.EXE ls-remote -h -t https://github.build.test.com/test.git
npm ERR!
npm ERR! remote: Password authentication is not available for Git operations.
npm ERR! remote: You must use a personal access token or SSH key.
npm ERR! remote: See https://github.build.test.com/settings/tokens or https://github.build.test.com/settings/ssh
npm ERR! fatal: unable to access 'https://github.build.test.com/test.git/': The requested URL returned error: 403
npm ERR!
npm ERR! exited with error code: 128

If I run above command separately, it works. 如果我单独运行上面的命令,它的工作原理。

git ls-remote -h -t https://<TOKEN>@github.build.test.com/test.git
git ls-remote -h -t ssh://git@github.build.test.com/test.git

How can I fix it? 我该如何解决?

Thanks 谢谢

First if you have any url.<base>.insteadOf directive in your git configuration: 首先,如果你的git配置中有任何url.<base>.insteadOf指令

cd /path/to/repo
git config -l|grep -i insteadOf

And if not, set one of your own: 如果没有,请设置一个:

git config url."ssh://git@github.build.test.com".insteadOf  https://github.build.test.com

See then if it is still using https. 如果它仍在使用https,请参阅。

If you are going to use "git+ssh://git@github.build.test.com/test.git" you should be able to clone this repository without passing credentials. 如果您打算使用“git + ssh://git@github.build.test.com/test.git”,您应该能够克隆此存储库而无需传递凭据。 Simple git clone git+ssh://git@github.build.test.com/test.git shouldn't ask for pass or username. 简单的git clone git+ssh://git@github.build.test.com/test.git不应该要求传递或用户名。

You probably need to configure your git public/private keys. 您可能需要配置您的git公钥/私钥。 Your locally used key for cloning must be added to repository config. 必须将本地使用的克隆密钥添加到存储库配置中。 For example for github is possible to configure it on https://github.com/settings/keys 例如,对于github,可以在https://github.com/settings/keys上配置它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Unable to install ansible collections from a private git repository using Https and SSH link - Unable to install ansible collections from a private git repository using Https and SSH link npm 使用 .git 文件夹和 .gitignore 文件安装私有 git 存储库 - npm install private git repository with .git folder and .gitignore file npm从私有gitlab安装git + ssh - npm install git+ssh from private gitlab Npm安装git https地址,但它查找SSH - Npm install git https address but it looks for SSH instead npm 从 git 安装使用 https 代替 Z1787D7646304C5D987ZCF4E64A3973DC7 - npm install from git use https instead ssh jenkins 中的私有 git npm 存储库的主机密钥验证失败 - Host key verification fails for a private git npm repository in jenkins npm从私有注册表安装回退到git存储库URL - npm install from private registry with fallback to a git repository URL 私有仓库,git clone 成功,npm install 失败 - Private repo, git clone succeeds, npm install fails 由于身份验证失败,在docker上参考私有存储库vsts git存储库运行package.json失败 - running package.json in docker with reference to a private repository vsts git repository fails due to authentication failure 为什么 npm 使用 git+ssh 安装与 https 不同? - Why does npm install with git+ssh install differently than https?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM