对于package.json中的git依赖关系,权限被拒绝

我尝试在package.json中设置git依赖关系:

"dependencies": { "myLib": "git+ssh://git@domain.com:user/myLib.git" } 

当我做sudo npm install出现错误:

 Warning: Permanently added the RSA host key for IP address 'myIp' to the list of known hosts. Permission denied (publickey). 

Allthough我可以成功克隆相同的lib到该机器:

 git clone git@domain.com:user/myLib.git 

所以我有有效的SSH密钥。

我的操作系统是OSX,但是在Linux上我有同样的问题。

我应该运行没有sudo npm install

如果不能,则更改node.js应用程序文件夹的权限:

 sudo chown -R `whoami` ~/pathToAll/node/apps. 

所以git的ssh依赖在package.json中运行良好

这是一个允许继续使用sudo npm install的解决scheme。

将以下内容添加到文本文件/root/.ssh/config

 Host domain.com User git Port 22 Hostname domain.com IdentityFile "/home/user/.ssh/id_rsa" TCPKeepAlive yes IdentitiesOnly yes StrictHostKeyChecking no 

即使使用sudo命令执行sudo npm install类的操作,此configuration也会引用原始密钥文件。