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

git push heroku master

但会出现以下错误:

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

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


当前回答

这是我的解决方案:

ssh-add ~/.ssh/my_heroku_key_rsa

其他回答

这个问题困扰了我几天。

这可能会有所帮助。

1) 看看你现在在Heroku有什么钥匙。

$ heroku keys
=== 1 key for joe@example.com
ssh-dss AAAAB8NzaC...DVj3R4Ww== joe@workstation.local

2) 构建~/.ssh/config文件:

$ sudo vim ~/.ssh/config

使用此信息编辑

Host heroku.com
Hostname heroku.com 
Port 22 
IdentitiesOnly yes 
IdentityFile ~/.ssh/ssh-dss # location and name of your private key
TCPKeepAlive yes 
User joe@workstation.local

这是我的解决方案:

ssh-add ~/.ssh/my_heroku_key_rsa

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

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

我希望这有帮助。

除了处理SSH密钥,您还可以尝试Heroku的新测试版HTTP Git支持。它只使用您的API令牌并在端口443上运行,因此无需使用SSH密钥或端口22。

要使用HTTP Git,首先确保Toolbelt已更新,并且您的凭据是最新的:

$ heroku update
$ heroku login

(这一点很重要,因为Heroku HTTP Git的认证方式与Toolbelt的其他方式略有不同)

在测试期间,通过将--httpgit标志传递给相关的heroku应用程序:create、heroku git:clone和heroku git:remote命令,可以获得HTTP。要创建新的应用程序并使用HTTP Git远程配置它,请运行以下命令:

$ heroku apps:create --http-git

要将现有应用程序从SSH更改为HTTP Git,只需从计算机上的应用程序目录运行以下命令:

$ heroku git:remote --http-git
Git remote heroku updated

有关如何为Heroku设置HTTP Git的详细信息,请查看开发中心文档。

在Windows 7,64位上,上面的解决方案(Onur Turhan的)对我很有效,有如下细微变化

C:\Users\MyName > heroku login

输入电子邮件/密码

C:\Users\MyName >ssh-keygen -t rsa -f id_rsa

这在我的c:\Users\MyName目录(不在.ssh目录中)中生成了两个文件(id_rsa和id_rsa.pub)

heroku keys:add id_rsa.pub
git clone git@heroku.com:some-heiku-xxxx.git -o heroku

我想添加正确的“id_rsa.pub”文件是最重要的。在使用keygen生成公钥后,只需查看创建时的时间戳,即可验证是否添加了正确的密钥。