我正在尝试使用以下命令行将代码部署到heroku:
git push heroku master
但会出现以下错误:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
我已经上传了我的公共SSH密钥,但仍然会出现此错误。
我正在尝试使用以下命令行将代码部署到heroku:
git push heroku master
但会出现以下错误:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
我已经上传了我的公共SSH密钥,但仍然会出现此错误。
当前回答
我也有同样的问题,下面的步骤对我有效,
->heroku login
abc@gmail.com密码(&P)
->cd C:\Users\yourusername\.ssh (OR for cygwin shell ->cd ~/.ssh)
->ssh密钥生成-t rsa-f id_rsa
如果询问任何密码,请不要使用空白,填写密码,但不要忘记。
生成密钥后,您需要添加它,如下所示
$ ssh-add
给heroku
->heroku keys:add "id_rsa.pub"
将目录更改为工作区,然后
->git clone git@heroku.com:stark-dawn-1234.git -o heroku
使用上面设置的密码短语。
实际上,我也删除了下面的文件,但不确定它们是imp,
C: \Users\yourusername.heroku\credientals和C:\Users\yourusername.ssh\known_hosts
其他回答
我面临的问题是在Windows上,每当我运行“heroku keys:add”时,它都会选择github键。以下是我解决问题的步骤
转到“Document and Settings”文件夹下的.ssh目录,删除了git hub密钥运行命令heroku键:添加
上面的命令要求我生成一个新的密钥,下面是输出找不到现有公钥。是否要生成一个?[Yn]是正在生成新的SSH公钥。正在上载SSH公钥C:\Documents and Settings/Admin/.SSH/id_rsa.pub…已完成! “heroku”gem已被弃用,取而代之的是heroku Toolbelt,请从https://toolbelt.heroku.com.
重新运行命令heroku键:添加
上述命令不会给出以下输出找到现有公钥:C:\Documents and Settings/Admin/.ssh/id_rsa.pub正在上载SSH公钥C:\Documents and Settings/Admin/.SSH/id_rsa.pub…已完成
现在使用git push heroku master
对我来说,使用上述步骤解决了问题,并能够在云上部署应用程序。
上面给出的答案确实有效,但我发现我需要做一些额外的步骤才能奏效。
我删除了所有id_rsa*文件,并使用本指南生成了一个新的SSH。然后,我销毁了heroku应用程序。删除了~/.heroku/credentials文件。“heroku create”命令(由于凭据文件已删除,它将提示您输入电子邮件/密码。最后键入“heroku-keys:add”,它将上载默认的~/.ssh/id_rsa.pub文件。它起作用了!好YMMV,但我真的希望这能对我有帮助,因为我一整天都在努力解决这个问题!哈哈
要遵循的顺序
$ heroku login
$ ssh-keygen -t rsa
$ heroku keys:add
当执行第二条语句时,它会要求输入,只需按Enter(回车)三次,就会添加一个键。
在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生成公钥后,只需查看创建时的时间戳,即可验证是否添加了正确的密钥。
您必须将公钥上传到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在错误目录中查找密钥的问题和解决方案。