通过npm访问Git仓库时出现Permission Denied权限拒绝问题
解决npm安装依赖时Git仓库权限拒绝问题
开头的npm WARN ERESOLVE overriding peer dependency是对等依赖版本冲突的警告,不影响本次安装失败的核心原因——你在通过npm拉取git@github.com/securedeveloper/js-xlsx.git仓库时,遇到了SSH权限拒绝的问题,本质是本地没有配置能访问该私有仓库的SSH密钥,或者密钥未被仓库授权。
完整错误日志
npm WARN ERESOLVE overriding peer dependency npm ERR! code 128 npm ERR! An unknown git error occurred npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/securedeveloper/js-xlsx.git npm ERR! git@github.com: 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! A complete log of this run can be found in: C:\Users\Jenil\AppData\Local\npm-cache\_logs\2024-02-12T05_18_59_027Z-debug-0.log
解决步骤
- 确认仓库访问权限:联系
securedeveloper/js-xlsx仓库的管理员,确认你已被添加为仓库成员并拥有读取权限。 - 配置SSH密钥:
- 检查本地是否有SSH公钥:打开终端执行
ls ~/.ssh,查看是否存在后缀为.pub的文件(比如id_rsa.pub、id_ed25519.pub)。 - 无公钥则生成新密钥:执行
ssh-keygen -t ed25519 -C "你的GitHub注册邮箱",全程按回车使用默认配置即可。 - 将公钥添加到GitHub账户:复制公钥内容(执行
cat ~/.ssh/id_ed25519.pub获取),登录GitHub后进入「Settings → SSH and GPG keys → New SSH key」,粘贴公钥内容并保存。
- 检查本地是否有SSH公钥:打开终端执行
- 测试SSH连接:终端执行
ssh -T git@github.com,如果返回Hi [你的GitHub用户名]! You've successfully authenticated, but GitHub does not provide shell access.,说明SSH配置正常。 - 临时改用HTTPS地址:如果SSH配置暂时无法搞定,可以把package.json里的依赖地址替换为HTTPS格式:
"xlsx": "git+https://github.com/securedeveloper/js-xlsx.git",安装时输入GitHub用户名和个人访问令牌(需要在GitHub的「Settings → Developer settings → Personal access tokens」生成)即可。
内容的提问来源于stack exchange,提问作者069_JENIL_ GODHANI
相关产品推荐
相关产品推荐

