npm 信任自签名证书

npm trust self-signed certificate

我在个人服务器上有一个 git 存储库,它使用自签名证书。

我想做的是将此 CA 添加到 npm 的受信任的 CA,以便像这样从 repo 安装软件包:

npm install git+https://domain.tld/repo.git

以下命令允许我信任我的服务器,但在那之后,我的本地 npm 不再信任 npm.org 存储库。

npm config set cafile=/usr/local/share/ca-certificates/domain.tld/ca.crt
npm config set ca="content-of-my-cert"

NB:它与 git+ssh:// 配合使用效果很好,但由于其他人会使用这个包,我不想每次都添加一个新的受信任的 ssh 密钥新消费者...

您对 cafile 和 ca 的设置正在清除默认的受信任 CA 证书。您可以使用 ca[] 数组信任多个 CA 证书,如下所示:

npm config set ca[]="content_of_your_CA_cert"
npm config set ca[]="content_of_the_npm_root_cert"
npm config set ca[]="content_of_the_npm_intermediate_cert"

P.S。 - npm.org 是全国田园音乐家协会。如果您的意思是 npmjs.com,则该证书 当前 由 DigiCert 使用 this intermediate cert and this root cert 签名。