我正在尝试使用以下命令行将代码部署到 heroku:
git push heroku master
但是得到以下错误:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
我已经上传了我的公共 SSH 密钥,但它仍然会出现此错误。
您必须将公钥上传到 Heroku:
heroku keys:add ~/.ssh/id_rsa.pub
如果您没有公钥,Heroku 将提示您自动添加一个公钥,无缝工作。只需使用:
heroku keys:add
清除以前的所有密钥:
heroku keys:clear
要显示所有现有密钥:
heroku keys
编辑:
以上似乎对我没有用。我弄乱了HOME
环境变量,所以 SSH 正在错误的目录中搜索密钥。
要确保 SSH 检查正确目录中的密钥,请执行以下操作:
ssh -vT [email protected]
这将显示以下(样本)行
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).
从上面你可以看到 ssh 查找/c/Wrong/Directory/.ssh
目录中的键,这不是我们刚刚添加到heroku keys:add ~/.ssh/id_rsa.pub
(使用heroku keys:add ~/.ssh/id_rsa.pub
)( 请注意,在 Windows OS 中~
指的是在 win C:\Users\UserName
为C:\Users\UserName
的HOME
路径 )
要查看当前的主目录,请执行以下操作: echo $HOME
或echo %HOME%
(Windows)
要正确设置HOME
目录(正确地说,我的意思是.ssh
目录的父目录,以便 ssh 可以在正确的目录中查找键)请参考以下链接:
我有同样的问题,下面的步骤对我有用,
->heroku login
->cd C:\Users\yourusername\.ssh (OR for cygwin shell ->cd ~/.ssh)
->ssh-keygen -t rsa -f id_rsa
如果要求任何密码不使用空白,请填写密码,但不要忘记密码。
生成密钥后,您需要添加它,就像这样
$ ssh-add
它和 heroku
->heroku keys:add "id_rsa.pub"
将目录更改为工作空间
->git clone [email protected]:stark-dawn-1234.git -o heroku
使用您在上面设置的密码。
其实我也删除下面的文件,但不确定它们是不是,
C:\ Users \ yourusername.heroku \ credientals 和 C:\ Users \ yourusername.ssh \ known_hosts
这个问题困扰了我几天。
这可能有所帮助。
1)找出你现在在 Heroku 中有哪些键。
$ heroku keys
=== 1 key for [email protected]
ssh-dss AAAAB8NzaC...DVj3R4Ww== [email protected]
2)构建一个〜/ .ssh / config 文件:
$ sudo vim ~/.ssh/config
使用此信息进行编辑
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]