Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
627 views
in Technique[技术] by (71.8m points)

git - 部署heroku代码时,权限被拒绝(公钥)。 致命:远端意外挂断(Permission denied (publickey) when deploying heroku code. fatal: The remote end hung up unexpectedly)

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密钥,但是它仍然出现此错误。)

  ask by community wiki translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

(如果您没有公共密钥,Heroku会提示您自动添加一个无缝运行的密钥。)

Just use:

(只需使用:)

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

(这将显示以下(示例)行)

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).

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的公共密钥的地方(使用heroku keys:add ~/.ssh/id_rsa.pub )( 请注意,在Windows OS中~指的是Windows heroku keys:add ~/.ssh/id_rsa.pub 中的C:\Users\UserNameHOME路径 ))

To view your current home directory do : echo $HOME or echo %HOME% ( Windows )

(要查看当前主目录,请执行以下操作: echo $HOMEecho %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可以在正确的目录中查找密钥),请参考以下链接:)

  1. SO Answer on how to set Unix environment variable permanently

    (SO答案关于如何永久设置Unix环境变量)

  2. SO Question regarding ssh looking for keys in the wrong directory and a solution for the same.

    (因此,关于ssh在错误目录中寻找密钥的问题及其解决方案。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...