Permission denied (publickey)

最近在push代码的时候时常会遇到问题,去google下,把别人的解决办法一个一个试,糊糊涂涂地解决了。

下次遇到的时候,还是要去google,原因是我不知道错误的真正原因,今天算是明白了点,所以我要把我明

白的东西记录下来,希望下次遇到的时候,能够快速解决。


ssh机制,简单的说,要使本地主机和远程服务器通过ssh连接,需要一对密钥,一个是私钥,存在于本地主

机,另一个是公钥,放在远程服务器,连接前还要确认ssh服务开启了没有(windows上运行的是ssh-agent.exe)


下面是我在使用git和heroku时曾遇到的问题

Permission denied (publickey).

fatal: The remote end hung up unexpectedly.


Permission denied (publickey).

fatal: Could not read from remote repository.


解决办法:请确保以下2步均做到

1、远程服务器已经有了对应于本地主机上公钥

2、本地主机ssh服务开启(windows上是ssh-agent.exe运行),并且本地主机私钥要包含在ssh服务列表中


具体细节:

为远程服务器(heroku)添加公钥的方法:可以到~/.ssh 下查看是否存在密钥对,如id_rsa和id_rsa.pub,可以

直接运行  

heroku keys:add

如果不存在的话,打命令生成一对

ssh-keygen -t rsa

然后再

heroku keys:add

检查本地私钥是否存在于ssh服务中

eval `ssh-agent -s`

如果运行这句出现Could not open a connection to your authentication agent,那么就先运行

ssh-agent bash

再运行

ssh-add -l

如果不存在,需要添加进去
ssh-add ~/.ssh/id_rsa
如果是push到git的话,给git添加公钥的话,可以手动把~/.ssh/id_rsa.pub的内容复制好,然后如下

Now that you have the key copied, it's time to add it into GitHub:

  1. Account settings buttonIn the user bar in the top-right corner of any page, click Account settings.
  2. SSH Keys menuClick SSH Keys in the left sidebar.
  3. SSH Key buttonClick Add SSH key.
  4. In the Title field, add a descriptive label for the new key. For example, if you're using a personal Mac, you might call this key "Personal MacBook Air".
  5. The key fieldPaste your key into the "Key" field.
  6. The Add key buttonClick Add key.
  7. Confirm the action by entering your GitHub password.


解决该问题方法链接如下,上面的内容都可以在下面的链接中找到(看链接最后几个单词可以知道该链接的内容)

http://www.cnblogs.com/sheldonxu/archive/2012/09/17/2688281.html

https://help.github.com/articles/error-permission-denied-publickey

https://help.github.com/articles/generating-ssh-keys

https://devcenter.heroku.com/articles/keys#adding-keys-to-heroku

http://stackoverflow.com/questions/4269922/permission-denied-publickey-when-deploying-heroku-code-fatal-the-remote-end

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值