解决git Permission denied (publickey). fatal问题

问题描述:

用自己的帐号创建git文件,但是因为用rez-release 需要root帐号release , root读不到我home下的~/.ssh 文件夹所以出现了fetch 时Permission denied (publickey). fatal的问题。
需要将 git 默认读取的.ssh文件指定到公共路径下
报错信息如下:

$ git fetch
Warning: Permanently added the RSA host key for IP address '192.30.255.113' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


解决方案:

- 第一步,创建新的ssh key

$ ssh-keygen -t rsa -C abc@email.com # git 邮箱 git config user.email
Generating public/private rsa key pair.
Enter file in which to save the key (/home/.../.ssh/id_rsa): /dev/new_ssh_file/.ssh/id_rsa # 将路径改为指定路径下

后面提示就直接回车就好

生成ssh key 后记得把 id_rsa 文件权限改称775

- 第二步,设置git上的ssh key

$ cat /dev/new_ssh_file/.ssh/id_rsa.pub

打开git网站 Account settings -> SSH and GPG keys -> SSH keys 点击 New SSH key , 将文件中的内容粘进去,并起个名字点击保存。通常内容是以“ssh-rsa”开头的
在这里插入图片描述

- 第三步,将新的ssh key 路径添加到默认路径中

分别在自己帐号和root帐号下进行如下操作

  1. 输入ssh -v git@github.com
    结果后两行应该是
>> debug1: No more authentication methods to try.
>> Permission denied (publickey).
  1. 紧接着输入 ssh-add /dev/new_ssh_file/.ssh/id_rsa
>> Identity added:/dev/new_ssh_file/.ssh/id_rsa (/dev/new_ssh_file/.ssh/id_rsa)

显示如上结果表示添加成功,紧接着用git clone 就可以克隆文件了。
如果显示

>> Could not open a connection to your authentication agent.

添加失败,则输入eval ˋssh-agent -sˋ 后再输入
ssh-add /dev/new_ssh_file/.ssh/id_rsa

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值