node.js - 以 sudo 身份运行 npm install 时 Git 身份验证失败

标签 node.js git npm

我正在尝试安装一个从我们的私有(private)存储库中提取的 npm 软件包。当我以自己的身份运行 npm install 时,我得到 Please try running this command again as root/Administrator.当我作为 sudo 运行它时,我得到

npm ERR! Error: Command failed: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.

我通常不使用 sudo 进行 npm install。我认为问题是当我以 sudo 身份运行时,它会在/var/root/.ssh 中查找 key 。我没有 root 用户凭据,否则我会以 root 身份创建一个新 key 。还有其他解决办法吗?

编辑:尝试了下面的建议,但没有用。但是,问题中的存储库是由包根目录下的依赖项引用的。 `./node_modules//package.json。如果我将 git url 更改为使用 http,它可以工作,但这样做不是一个好主意,因为当我将包签回存储库时,我必须更改它。

最佳答案

试试这个: sudo/bin/bash 然后,运行 npm 命令

关于node.js - 以 sudo 身份运行 npm install 时 Git 身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35076249/

相关文章:

node.js - 没有NodeJS的vue文件?

node.js - 全局 NPM 包安装的简单 CircleCI 2.0 配置失败

javascript - 安装 angularjs2 cli 时 npm 不工作 - “read ECONNRESET”

Git 和 Mercurial - 有人可以解释这个测试结果吗

Windows 上的 NPM 日志?

javascript - 返回 Promise.all 不执行提供的 Promise

javascript - Node JS 和 C# 中的 AES 加密给出了不同的结果

angularjs - 环回中的动态 datasource.json

git - 无法跟踪 Git 子模块中的文件

Git pull 在工作树 : Not a git repository (or any of the parent directories) 上失败