Mac npm install时提示[email protected]:Permission denied (publickey)

npm安装truffle-contract时报如下错误

% npm install truffle-contract --save                                  

npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/web3-js/WebSocket-Node.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:
npm ERR!     /Users/domino/.npm/_logs/2023-01-25T09_49_32_140Z-debug-0.log

原因是没有配置 github的ssh key,没有权限通过ssh下载github上的项目。

解决方法:

  • 生成ssh key

    .ssh % ssh-keygen -t rsa -b 4096 -C "你的邮箱@163.com"
    Generating public/private rsa key pair.
    # 这里要输入rsa文件的位置,注意不要覆盖掉默认的,避免影响到已有的ssh连接
    Enter file in which to save the key (/Users/domino/.ssh/id_rsa): /Users/domino/.ssh/id_rsa_github
    # 直接回车到底
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /Users/domino/.ssh/id_rsa_github.
    Your public key has been saved in /Users/domino/.ssh/id_rsa_github.pub.
    The key fingerprint is:
    SHA256:0qmF2i4vW05EYxIZJv1TI5wv1zRldtmh1GDLp5g9mM0 xxxx@163.com
    The key's randomart image is:
    ………………
    
  • 配置到 ~/.ssh/config文件中

    # 在 ~/.ssh/config文件中添加以下代码,如果没有则需要先创建
    
    #github
    Host *.github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_github
    

配置好重新执行安装命令,安装成功

% npm install truffle-contract --save
npm WARN deprecated uuid@2.0.1: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid@2.0.1: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid@2.0.1: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated uuid@3.3.2: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated truffle-interface-adapter@0.2.5: WARNING: This package has been renamed to @truffle/interface-adapter.
npm WARN deprecated uuid@3.3.2: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated truffle-contract@4.0.31: WARNING: This package has been renamed to @truffle/contract.

added 196 packages in 42s

参考文档:
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
https://blog.csdn.net/huangsy421/article/details/121489441

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值