NPM 安装错误本地存储库的权限被拒绝(公钥) [英] NPM install error Permission denied (publickey) for local repo

查看:40
本文介绍了NPM 安装错误本地存储库的权限被拒绝(公钥)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我公司的 github 中获取本地存储库的权限被拒绝错误,我可以成功克隆,但是安装 NPM 时出错:

Getting permission denied error for a local repo in my company github, which I can clone successfully, however getting error for NPM install:

npm ERR! Error while executing:
npm ERR! C:\Program Files\Git\bin\git.EXE ls-remote -h -t git@<repo path and name>
npm ERR!
npm ERR! 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.
npm ERR!
npm ERR! exited with error code: 128

推荐答案

我遇到了这个问题并且无法修复,因为所有解决方案都缺少一个重要步骤,所以我将更详细地发布我的答案.

I ran into this problem and was not able to fix as all the solutions lacked one important step, so I am posting my answer in greater detail.

假设您已经生成了 ssh-key 并将其公钥添加到您的 github 帐户.另外,假设您使用的是 Windows-10.

Assuming you have already generated ssh-key and added its public key to your github account. Also, assuming you are using Windows-10.

npm install 在 Windows 上会导致很多问题,因为 ssh-agent 从 2 个不同的来源运行:

npm install on Windows causes a lot of problems because there are ssh-agents running from 2 different sources:

  • Windows 提供了 ssh-agent (OpenSSH).此功能是在 Windows-10 更新之一中添加的,是罪魁祸首.:)
  • Git ssh-agent(您的场景需要这个)(假设安装了 git.)
  • 在 cmd 中运行 start-ssh-agent(运行 git 提供的 ssh-agent)和 ssh-agent(运行 Windows 提供的 ssh-agent).

  • Run start-ssh-agent (to run git provided ssh-agent) and ssh-agent (to run Windows provided ssh-agent) in cmd.

转到任务管理器并单击详细信息选项卡.

Go to task manager and click on details tab.

查找 ssh-agent.exe.

Look for ssh-agent.exe.

完成以上步骤后,您可以看到 2 个 ssh-agent.exe 正在运行.在用户名"列中,您可以看到一个用于 SYSTEM(由 Windows 提供)和一个用于您的用户名(这是 git).现在,请关闭您为 npm install 启动的所有 ssh-agents(直接从任务管理器中).

After following above steps, you can see 2 ssh-agent.exe running. In the 'User name' column you can see one for SYSTEM (this is provided by Windows) and one for your-user-name (this is git). Now, please close all ssh-agents you started for npm install(directly from task manager).

npm install 尝试使用的 ssh-agent 来自 git,但它与 Windows 提供的 ssh-agent 冲突.

ssh-agent that npm install is trying to use is from the git but it is being conflicted with the windows provided ssh-agent.

Git ssh-agent 可以使用 start-ssh-agent 启动,但是当您尝试使用命令 ssh-add -k ~/.ssh/id_rsa,它试图从 Windows 路径访问 ssh-add.exe,但没有从 git 中选择 ssh-add.exe.

Git ssh-agent can be started using start-ssh-agent but when you try to add ssh-key to your ssh-agent using command ssh-add -k ~/.ssh/id_rsa, it is trying to access ssh-add.exe from Windows path but not picking ssh-add.exe from git.

解决办法是将git的ssh路径添加到你系统的环境变量中,并添加在%SYSTEMROOT%\System32\OpenSSH"之前所以它具有更高的优先级.

Solution is to add ssh path of git to the Environment variables of your system and adding it before the "%SYSTEMROOT%\System32\OpenSSH" so it has higher priority.

这只是为了您可以访问 git 的 ssh-add.exe 并且在成功 npm build 后您可以自由删除它(即使您想克隆更多 repos 并构建它们).除非您想为不同的存储库添加更多密钥.

This is only required so that you can access ssh-add.exe of git and after successful npm build you can freely remove it(even if you want to clone more repos and build them). Unless you want to add more keys for different repos.

注意:此路径与在 git 安装期间添加的已经存在的 git/cmd 路径不同,因此请确保将其添加 before openSSH 路径变量以获得更高的优先级.

Note: This path is different from the already present git/cmd path added during git installation so please make sure it is added before openSSh path variable for higher priority.

请按照以下步骤解决您的问题:

Please follow below steps to resolve your issue:

  1. 通过在 cmd 中运行 start-ssh-agent 来启动您的 git ssh-agent.不要使用 ssh-agent,因为它会启动 Windows 提供的 ssh-agent.
  2. 打开任务管理器并转到详细信息标签.
  3. 查找 ssh-agent.exe.
  4. 右键单击 ssh-agent.exe(在 git 提供的那个上),然后单击打开文件位置.
  5. 复制路径并将其添加到系统的环境变量中.请确保将此路径移至%SYSTEMROOT%\System32\OpenSSH"上方.(如果已经存在则忽略).
  6. 关闭 cmd 并从任务管理器中关闭正在运行的 ssh-agent.exe.注意:Env 需要关闭 cmd.变量生效.
  7. 在您的存储库中打开 cmd 并运行 where ssh-agentwhere ssh-add 以测试首选的 ssh 路径.(希望您现在看到 2 个路径,并且 OpenSSH 不应出现在 Git/bin/usr 路径之前:)
  8. 现在,你完成了.运行 start-ssh-agent.(运行 git ssh-agent)
  9. 通过 ssh-add -k ~/.ssh/id_rsa 将您喜欢的 ssh 密钥添加到您的 ssh-agent.(选择私钥).(将密钥添加到 git ssh-agent,而不是 Windows ssh-agent)
  10. 添加成功后,运行 npm install.
  1. Start your git ssh-agent by running start-ssh-agent in cmd. Don't use ssh-agent as it starts the Windows provided ssh-agent.
  2. Open Task Manager and go to Details tab.
  3. Look for ssh-agent.exe.
  4. Right click on ssh-agent.exe(on the one provided by git) and click open file location.
  5. Copy the path and add it to Environment variables for system. Please make sure you move this path above "%SYSTEMROOT%\System32\OpenSSH".(Ignore if already present).
  6. Close cmd and also close the running ssh-agent.exe from task manager. Note: Closing cmd is required for Env. variables to take effect.
  7. Open cmd in your repo and run where ssh-agent and where ssh-add to test which ssh path will be preferred. (Hope you see 2 paths now and OpenSSH should not be appearing before Git/bin/usr path :) )
  8. Now, you are done. Run start-ssh-agent.(Runs git ssh-agent)
  9. Add your preferred ssh key to you ssh-agent by ssh-add -k ~/.ssh/id_rsa.(choose private key). (Adds keys to git ssh-agent, not Windows ssh-agent)
  10. Once successfully added, run npm install.

注意:此后,每当您再次看到相同的错误时,只需运行 start-ssh-agent,然后运行 ​​npm install.

Note: After this, whenever you see the same error again, just run start-ssh-agent and then npm install.

我希望它有效,如果你不舒服,在成功构建 npm 后,你甚至可以从 env 中删除新添加的路径.变量,因为它只需要一次(从 gi​​t 访问 ssh-add),并且 start-ssh-agent 不能从该路径访问.

I hope it works, and if you are not comfortable, after successful npm build you can even remove the newly added path from env. variables as it was required only once(to access ssh-add from git), and start-ssh-agent is not accessed from that path.

删除路径不会有影响,但我建议不要删除路径,因为此路径还有许多其他有用的工具,例如 perl.exe、openssl.exe(不要不需要单独安装这些工具).

It won't affect if you delete the path but I would recommend not to delete the path as this path also has many other useful tools like perl.exe, openssl.exe (don't need to install these tools separately).

这篇关于NPM 安装错误本地存储库的权限被拒绝(公钥)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆