解决git clone提示Permission denied publickey 问题


http://bbs.gsmcn.cn/thread-2474-1-1.html 


偶然编译中文recovery时候遇到了一个错误.后来尝试了一下.解决了,在这里记录分享一下


root@htcdev-VirtualBox:~/Rec_folder# git clone git@github.com:APAR1992/CWM_Recovery_v6037_cn.git
Cloning into 'CWM_Recovery_v6037_cn'...
The authenticity of host 'github.com (192.30.252.131)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.131' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
root@htcdev-VirtualBox:~/Rec_folder# 

报错看来是跟publickey有关系
首先来github的解决中心来看 跟着教程走
https://help.github.com/articles/generating-ssh-keys

  1. root@htcdev-VirtualBox:~# cd ~/.ssh
  2. root@htcdev-VirtualBox:~/.ssh# ls
  3. known_hosts
  4. root@htcdev-VirtualBox:~/.ssh# ssh-keygen -t rsa -C recovery@gsmcn.cn  
  5. Generating public/private rsa key pair.
  6. Enter file in which to save the key (/root/.ssh/id_rsa): 
  7. Enter passphrase (empty for no passphrase): 
  8. Enter same passphrase again: 
  9. Your identification has been saved in /root/.ssh/id_rsa.
  10. Your public key has been saved in /root/.ssh/id_rsa.pub.
  11. The key fingerprint is:
  12. 0b:3a:6d:6e:63:e5:6c:a1:1e:1d:c0:61:73:60:5d:d9 recovery@gsmcn.cn
  13. The key's randomart image is:
  14. +--[ RSA 2048]----+
  15. |      *o...o     |
  16. |     + +. . E    |
  17. |      o          |
  18. |       .         |
  19. |      . S        |
  20. |     o ooo       |
  21. |    o +=o.       |
  22. |     +=.+        |
  23. |     +oo         |
  24. +-----------------+
  25. root@htcdev-VirtualBox:~/.ssh# 
复制代码
这里ssh-keygen -t rsa -C "Your@Your.com" 替换为你的邮箱地址,别的都为空,直接回车,就会提示你生成完毕



紧接着执行
  1. ssh-add id_rsa
复制代码
然后系统会提示你
  1. root@htcdev-VirtualBox:~/.ssh# ssh-add id_rsa
  2. Identity added: id_rsa (id_rsa)
复制代码




然后我们去github保存你的ssh key
登录github.com --AccountSetting--ssh  点击Add
然后输入我们刚才计算的key

这里有个简单的复制方法 打开终端 输入
  1. sudo apt-get install xclip
复制代码

然后执行
  1. xclip -sel clip < ~/.ssh/id_rsa.pub
复制代码

直接在key那里右键粘贴 Title随意写。。。



到这里 我们的ssh key 就算添加完毕了
现在去同步下代码看看,终于可以同步了!~




测试环境 ubuntu12.04
 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当您克隆一个 Git 仓库时,出现 "Permission denied (publickey)" 错误,通常是由于 SSH 密钥认证失败导致的。 要解决这个问题,您可以按照以下步骤操作: 1. 检查 SSH 密钥:首先,确认您的系统上是否存在 SSH 密钥对(公钥和私钥)。您可以使用以下命令检查: ``` ls -al ~/.ssh ``` 如果不存在密钥对,请生成一个新的 SSH 密钥。可以使用以下命令生成: ``` ssh-keygen -t rsa -b 4096 -C "your_email@example.com" ``` 这将在 `~/.ssh` 文件夹中生成一个新的密钥对。 2. 添加 SSH 公钥到 Git 仓库:将公钥内容复制到剪贴板中,并登录到您使用的 Git 仓库托管服务(如 GitHub、GitLab、Bitbucket)的网站。 在该网站的设置中,找到 SSH 密钥选项,并将公钥粘贴到相应的字段中。 3. 验证 SSH 连接:使用以下命令验证 SSH 连接是否正常: ``` ssh -T git@github.com ``` 如果连接成功,您将看到一条欢迎信息。 4. 使用 SSH URL 克隆仓库:最后,使用 SSH URL 克隆仓库。确保使用 `git clone` 命令时使用 SSH URL,而不是 HTTPS URL。例如: ``` git clone git@github.com:username/repo.git ``` 这将使用 SSH 协议克隆仓库,并使用您的 SSH 密钥进行认证。 如果问题仍然存在,请确保您正确设置了 SSH 密钥,并且在 Git 仓库托管服务上正确添加了公钥。如果问题仍然无法解决,请提供更多详细信息,以便我可以更好地帮助您解决问题

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值