部署 heroku 代码时权限被拒绝公钥致命:远端意外挂断

问题描述

您必须将您的公钥上传到 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/Wrong/Directory/.ssh目录中没有我们刚刚添加到 heroku 的公钥(使用heroku keys:add ~/.ssh/id_rsa.pub)( )

要查看您当前的主目录,请执行以下操作:echo $HOMEecho %HOME%(Windows)

要正确设置您的HOME目录(正确的意思是目录的父目录.ssh,以便 ssh 可以在正确的目录中查找密钥)

解决方法

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

git push heroku master

但得到以下错误:

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

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...