Permission denied (publickey) when deploying heroku code. fatal: The remote end hung up unexpectedly Permission denied (publickey) when deploying heroku code. fatal: The remote end hung up unexpectedly heroku heroku

Permission denied (publickey) when deploying heroku code. fatal: The remote end hung up unexpectedly


You have to upload your public key to 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 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.

To ensure that SSH checks for the key in the correct directory do :

ssh -vT git@heroku.com

Which will display the following ( Sample ) lines

OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007debug1: Connecting to heroku.com [50.19.85.156] port 22.debug1: Connection established.debug1: identity file /c/Wrong/Directory/.ssh/identity type -1debug1: identity file /c/Wrong/Directory/.ssh/id_rsa type -1debug1: identity file /c/Wrong/Directory/.ssh/id_dsa type -1debug1: Remote protocol version 2.0, remote software version Twisteddebug1: no match: Twisteddebug1: Enabling compatibility mode for protocol 2.0debug1: Local version string SSH-2.0-OpenSSH_4.6debug1: SSH2_MSG_KEXINIT sentdebug1: SSH2_MSG_KEXINIT receiveddebug1: kex: server->client aes128-cbc hmac-md5 nonedebug1: kex: client->server aes128-cbc hmac-md5 nonedebug1: sending SSH2_MSG_KEXDH_INITdebug1: expecting SSH2_MSG_KEXDH_REPLYdebug1: Host 'heroku.com' is known and matches the RSA host key.debug1: Found key in /c/Wrong/Directory/.ssh/known_hosts:1debug1: ssh_rsa_verify: signature correctdebug1: SSH2_MSG_NEWKEYS sentdebug1: expecting SSH2_MSG_NEWKEYSdebug1: SSH2_MSG_NEWKEYS receiveddebug1: SSH2_MSG_SERVICE_REQUEST sentdebug1: SSH2_MSG_SERVICE_ACCEPT receiveddebug1: Authentications that can continue: publickeydebug1: Next authentication method: publickeydebug1: Trying private key: /c/Wrong/Directory/.ssh/identitydebug1: Trying private key: /c/Wrong/Directory/.ssh/id_rsadebug1: Trying private key: /c/Wrong/Directory/.ssh/id_dsadebug1: 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 )

To view your current home directory do : echo $HOME or 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 :

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

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


I had the same issue, the steps below worked for me,

->heroku login

abc@gmail.com & password

->cd C:\Users\yourusername\.ssh    (OR for cygwin shell ->cd ~/.ssh)

->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 keys:add "id_rsa.pub"

change directory to workspace, than

->git clone git@heroku.com: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


This problem was messing with me for a few days.

This might help.

1) Find out what keys you have in Heroku now.

$ heroku keys=== 1 key for joe@example.comssh-dss AAAAB8NzaC...DVj3R4Ww== joe@workstation.local

2) Build a ~/.ssh/config file:

$ sudo vim ~/.ssh/config

Edit with this info

Host heroku.comHostname heroku.com Port 22 IdentitiesOnly yes IdentityFile ~/.ssh/ssh-dss # location and name of your private keyTCPKeepAlive yes User joe@workstation.local