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

git push heroku master

但会出现以下错误:

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

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


当前回答

对于那些在Windows7上尝试了上述所有方法但仍然没有成功的人,我做了以下工作:-从Git目录C:\Program Files(x86)\Git\中打开GitBash.exe(不要打开命令提示符,这不起作用)。-如上所述添加以下内容,但必须删除#

Host heroku.com
Hostname heroku.com 
Port 22 
IdentitiesOnly yes 
IdentityFile ~/.ssh/ssh-dss
TCPKeepAlive yes 
User joe@workstation.local

现在运行gitpushherokumaster,它应该可以工作了。

其他回答

您必须将公钥上传到Heroku:

heroku keys:add ~/.ssh/id_rsa.pub

如果您没有公钥,Heroku将提示您自动添加一个,这可以无缝工作。只需使用:

heroku keys:add

要清除所有以前的关键点,请执行以下操作:

heroku keys:clear

要显示所有现有密钥,请执行以下操作:

heroku keys

编辑:

上面的内容似乎对我不起作用。我在HOME环境变量上搞砸了,所以SSH在错误的目录中搜索密钥。

要确保SSH检查正确目录中的密钥,请执行以下操作:

ssh -vT git@heroku.com

将显示以下(示例)行

OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Connecting to heroku.com [50.19.85.156] port 22.
debug1: Connection established.
debug1: identity file /c/Wrong/Directory/.ssh/identity type -1
debug1: identity file /c/Wrong/Directory/.ssh/id_rsa type -1
debug1: identity file /c/Wrong/Directory/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version Twisted
debug1: no match: Twisted
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Host 'heroku.com' is known and matches the RSA host key.
debug1: Found key in /c/Wrong/Directory/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /c/Wrong/Directory/.ssh/identity
debug1: Trying private key: /c/Wrong/Directory/.ssh/id_rsa
debug1: Trying private key: /c/Wrong/Directory/.ssh/id_dsa
debug1: No more authentication methods to try.

权限被拒绝(公钥)。

从上面的内容中,您可以观察到ssh在/c/Virn/Directory/.ssh目录中查找密钥,而不是我们刚才添加到heroku的公钥所在的位置(使用heroku密钥:add~/.ssh/id_rsa.pub)(请注意,在windows操作系统中~指的是HOME路径,在win 7/8中是c:\Users\UserName)

要查看当前主目录,请执行以下操作:echo$home或echo%home%(Windows)

要正确设置HOME目录(正确地说,我指的是.ssh目录的父目录,以便ssh可以在正确的目录中查找密钥),请参考以下链接:

SO回答如何永久设置Unix环境变量所以关于ssh在错误目录中查找密钥的问题和解决方案。

我有同样的问题,因为我没有公钥,所以我做到了:

heroku keys:clear
heroku keys:add

这将生成公钥,然后工作正常

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

 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

这应该奏效。

推送时使用

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

我也遇到了同样的问题;以下步骤将有助于:

首先,登录:heroku登录清除所有键:heroku键:清除删除.ssh/文件夹中本地文件夹中的所有文件(所有.pub文件和know_host)再次登录:heroku login-u将无需按键提示,因此请按照屏幕上的说明进行操作。