git 部署 heroku 代码时权限被拒绝(公钥)。致命:远端意外挂断
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4269922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Permission denied (publickey) when deploying heroku code. fatal: The remote end hung up unexpectedly
提问by vich
I'm attempting to deploy my code to heroku with the following command line:
我正在尝试使用以下命令行将我的代码部署到 heroku:
git push heroku master
but get the following error:
但得到以下错误:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
I have already uploaded my public SSH key, but it still comes up with this error.
我已经上传了我的公共 SSH 密钥,但它仍然出现此错误。
回答by sebarmeli
You have to upload your public key to Heroku:
您必须将您的公钥上传到 Heroku:
heroku keys:add ~/.ssh/id_rsa.pub
If you don't have a public key, Heroku will prompt you to add one automatically which works seamlessly. Just use:
如果您没有公钥,Heroku 会提示您自动添加一个可以无缝工作的公钥。只需使用:
heroku keys:add
To clear all your previous keys do :
要清除所有以前的键,请执行以下操作:
heroku keys:clear
To display all your existing keys do :
要显示所有现有的密钥,请执行以下操作:
heroku keys
EDIT:
编辑:
The above did not seem to work for me. I had messed around with the HOME
environment variable and so SSH was searching for keys in the wrong directory.
以上似乎对我不起作用。我弄乱了HOME
环境变量,所以 SSH 在错误的目录中搜索密钥。
To ensure that SSH checks for the key in the correct directory do :
要确保 SSH 检查正确目录中的密钥,请执行以下操作:
ssh -vT [email protected]
Which will display the following ( Sample ) lines
这将显示以下 ( Sample ) 行
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.
Permission denied (publickey).
Permission denied (publickey).
From the above you could observe that ssh looks for the keys in the /c/Wrong/Directory/.ssh
directory which is not where we have the public keys that we just added to heroku ( using heroku keys:add ~/.ssh/id_rsa.pub
) ( Please note that in windows OS ~
refers to the HOME
path which in win 7 / 8 is C:\Users\UserName
)
从上面你可以观察到 ssh 在/c/Wrong/Directory/.ssh
目录中查找密钥,该目录不是我们刚刚添加到 heroku 的公钥( using heroku keys:add ~/.ssh/id_rsa.pub
)(请注意,在 Windows 操作系统~
中指的是HOME
win 7 / 8 中的路径是C:\Users\UserName
)
To view your current home directory do : echo $HOME
or echo %HOME%
( Windows )
要查看您当前的主目录,请执行以下操作:echo $HOME
或echo %HOME%
(Windows)
To set your HOME
directory correctly ( by correctly I mean the parent directory of .ssh
directory, so that ssh could look for keys in the correct directory ) refer these links :
要HOME
正确设置您的目录(正确地我指的是.ssh
目录的父目录,以便 ssh 可以在正确的目录中查找密钥)请参考以下链接:
回答by Onur Turhan
I had the same issue, the steps below worked for me,
我遇到了同样的问题,以下步骤对我有用,
->heroku login
[email protected] & password
->cd C:\Users\yourusername\.ssh (OR for cygwin shell ->cd ~/.ssh)
->ssh-keygen -t rsa -f id_rsa
->ssh-keygen -t rsa -f id_rsa
if asks any passphrase don't use blank, fill with a passphrase,but not forget it.
如果要求任何密码短语不要使用空白,请填写密码短语,但不要忘记它。
After generating the key you need to add it, like so
生成密钥后,您需要添加它,就像这样
$ ssh-add
and it to heroku
然后到heroku
->heroku keys:add "id_rsa.pub"
change directory to workspace, than
将目录更改为工作区,而不是
->git clone [email protected]:stark-dawn-1234.git -o heroku
use passphrase that you set above.
使用您在上面设置的密码。
Actually i also remove files below, but not sure that they are imp,
其实我也删除了下面的文件,但不确定它们是小鬼,
C:\Users\yourusername.heroku\credientals and C:\Users\yourusername.ssh\known_hosts
C:\Users\yourusername.heroku\credientals 和 C:\Users\yourusername.ssh\known_hosts
回答by jkpham
This problem was messing with me for a few days.
这个问题困扰了我几天。
This might help.
这可能会有所帮助。
1) Find out what keys you have in Heroku now.
1) 找出您现在在 Heroku 中拥有的密钥。
$ heroku keys
=== 1 key for [email protected]
ssh-dss AAAAB8NzaC...DVj3R4Ww== [email protected]
2) Build a ~/.ssh/config file:
2) 建立一个 ~/.ssh/config 文件:
$ sudo vim ~/.ssh/config
Edit with this info
使用此信息进行编辑
Host heroku.com
Hostname heroku.com
Port 22
IdentitiesOnly yes
IdentityFile ~/.ssh/ssh-dss # location and name of your private key
TCPKeepAlive yes
User [email protected]
回答by Lithium
Here is the link that explains how to manage your ssh keys: https://devcenter.heroku.com/articles/keys#adding-keys-to-heroku
这是解释如何管理 ssh 密钥的链接:https: //devcenter.heroku.com/articles/keys#adding-keys-to-heroku
回答by Stefan Manastirliu
I had the same problem cause i had no public keys, so i did:
我遇到了同样的问题,因为我没有公钥,所以我做了:
heroku keys:clear
heroku keys:add
That will generate a public key and then it works well
这将生成一个公钥,然后它运行良好
回答by Leo
If you are a windows user the other solutions here probably won't solve your problem.
如果您是 Windows 用户,这里的其他解决方案可能无法解决您的问题。
I use Windows 7 64-Bit + Git-1.7.7.1-preview20111027 and the solution was to copy my keys from C:\users\user\.ssh
to C:\Program Files (x86)\Git\.ssh
. That's where this git client looks for the keys when pushing to heroku.
我使用的是Windows 7 64位+的Git-1.7.7.1-preview20111027和解决方案是我的钥匙从复制C:\users\user\.ssh
到C:\Program Files (x86)\Git\.ssh
。这就是这个 git 客户端在推送到 heroku 时寻找密钥的地方。
I hope this helps.
我希望这有帮助。
回答by Gabor
This was the solution for me:
这对我来说是解决方案:
ssh-add ~/.ssh/my_heroku_key_rsa
回答by Maxence
To share my experience :
分享我的经验:
Git (my own install) was looking for the key named 'id_rsa'.
Git(我自己的安装)正在寻找名为“id_rsa”的密钥。
So I tried to rename my keys to 'id_rsa' and 'id_rsa.pub'and it worked.
所以我尝试将我的密钥重命名为 'id_rsa' 和 'id_rsa.pub'并且它起作用了。
Btw, I'm sure there is an other way to do it but I didn't look deeper yet.
顺便说一句,我确定还有其他方法可以做到,但我还没有深入研究。
回答by Srinivas Kattimani
If you've already uploaded the key then try to remove the key and then re-upload it with a new key.
如果您已经上传了密钥,请尝试删除密钥,然后使用新密钥重新上传。
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
this should work.
这应该有效。
回答by Sauce McBoss
I killed myself for 3 days trying every possible combination to try to get this to work -- I finally tried making a DSAkey instead and it worked.
我自杀了 3 天,尝试了所有可能的组合来尝试让它发挥作用——我最终尝试制作一个DSA密钥并且它起作用了。
Try DSA instead of RSA if it's not working for you.
如果它不适合您,请尝试使用 DSA 而不是 RSA。
(I'm using Ubuntu 11.10, ruby 1.8.7, heroku 2.15.1)
(我使用的是 Ubuntu 11.10、ruby 1.8.7、heroku 2.15.1)