问题描述:
用自己的帐号创建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帐号下进行如下操作
- 输入
ssh -v git@github.com
结果后两行应该是
>> debug1: No more authentication methods to try.
>> Permission denied (publickey).
- 紧接着输入
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