我正在尝试使用以下命令行将代码部署到heroku:

git push heroku master

但会出现以下错误:

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

我已经上传了我的公共SSH密钥,但仍然会出现此错误。


当前回答

推送时使用

git push heroku production:master 

使用主目录~/.ssh/id_rsa下的公钥

要解决此问题

您应该以其他用户身份登录,可能是root用户

sudo su 

然后通过发出以下命令重新开始

heroku keys:clear //removes existing keys
ssh-keygen -t rsa //generates a new key in ~/.ssh folder (set a password)
heroku keys:add   //uploads the new key, ~/.ssh/id_rsa is uploaded                      
git push heroku production:master

其他回答

我也有这个问题。我正在使用Mac OSX。我解决的方法是以管理员身份登录

获取权限暗语

推对我很有效,然后突然停了下来。

如果heroku api正在经历宕机,那么当您尝试推送时会出现此错误。

检查:

https://status.heroku.com/

在极度紧张之前。

如果您已上载密钥,请尝试删除密钥,然后重新上载它有一把新钥匙。

 heroku keys:remove //removes the existing key
 ssh-keygen -t rsa //generates a new key in ~/.ssh folder
 heroku keys:add    //uploads the new key, if no arguments r passed then the key generated                              
                    //in default directroy i.e., ~/.ssh/id_rsa is uploaded
 git push heroku

这应该奏效。

如果您是windows用户,这里的其他解决方案可能无法解决您的问题。

我使用的是Windows 7 64位+Git-1.7.7.1-review20111027,解决方案是将我的密钥从C:\users\user\.ssh复制到C:\Program Files(x86)\Git\.ssh。这是Git客户端在推送到heroku时查找密钥的地方。

我希望这有帮助。

我重新安装了heroku工具带,它工作了。