I’m attempting to deploy my code to heroku with the following command line:
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.
You have to upload your public key to Heroku:
If you don’t have a public key, Heroku will prompt you to add one automatically which works seamlessly. Just use:
To clear all your previous keys do :
To display all your existing keys do :
EDIT:
The above did not seem to work for me. I had messed around with the
HOMEenvironment 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 :
Which will display the following ( Sample ) lines
Permission denied (publickey).From the above you could observe that ssh looks for the keys in the
/c/Wrong/Directory/.sshdirectory which is not where we have the public keys that we just added to heroku ( usingheroku keys:add ~/.ssh/id_rsa.pub) ( Please note that in windows OS~refers to theHOMEpath which in win 7 / 8 isC:\Users\UserName)To view your current home directory do :
echo $HOMEorecho %HOME%( Windows )To set your
HOMEdirectory correctly ( by correctly I mean the parent directory of.sshdirectory, so that ssh could look for keys in the correct directory ) refer these links :SO Answer on how to set Unix environment variable permanently
SO Question regarding ssh looking for keys in the wrong directory and a solution for the same.