remote - ssh github heroku

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

At first make sure hidden files are visible in your Mac. If not do:

  • Open terminal and type in defaults write AppleShowAllFiles TRUE
  • killall Finder

Next steps:

  • Going to Users/user_name/.ssh/ removed all the files.
  • Opening terminal type in ssh-keygen -t dsa
  • Then heroku keys:add ~/.ssh/

N.B. I did it in Mac OSX 10.7.2 Lion. Though the procedure should be same in others too.

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.

Check your .ssh config for heroku. Go to the .ssh folder and open the config file

cd ~/.ssh
subl config

The 'subl' is for Sublime Text, but you can use whatever editor you wish. Look for the line "IdentityFile" and make sure it has the non public key listed:

IdentityFile "/Users/ircmullaney/.ssh/my_ssh"


IdentityFile "/Users/ircmullaney/.ssh/"

That did it for me. I'm not sure why mine had the public version in the config file, but it did and it was throwing the error:

Permissions 0644 for '/Users/ircmullaney/.ssh/' are too open.

Here is what worked for me. The heroku site is not being added to your known hosts. Go to window-other- show view-git-git repositories. From there clone the repository. Once you clone it, delete the repository that was just created and then import it from the file menu. Do this since when you clone the repository, it does not add it to the explorer view. Now you should have the git repository and the explorer view.

I had the same problem cause i had no public keys, so i did:

heroku keys:clear
heroku keys:add

That will generate a public key and then it works well

I had this problem when TortoiseGIT was installed on my machine. After changing the environment variable GIT_SSH from

"c:\Program Files\TortoiseGit\bin\TortoisePlink.exe"


"c:\Program Files (x86)\Git\bin\ssh.exe"

and following this tutorial with ssh-keygen and keys:add, it works!

I have this issue as well. I am using Mac OSX. The way I fixed that was to login as admin

sudo su


I killed myself for 3 days trying every possible combination to try to get this to work -- I finally tried making a DSA key instead and it worked.

Try DSA instead of RSA if it's not working for you.

(I'm using Ubuntu 11.10, ruby 1.8.7, heroku 2.15.1)

I was still having problems after trying all of these ideas. This was my problem:

My remote heroku repository was funked. I refreshed it as follows:

git remote -v

Then remove the heroku one that is wrong:

git remote rm heroku

Then add the new one

git remote add heroku [email protected]:sitename.git

You can get the sitename from your Heroku settings page for your app. Good Luck!

I would just to like to add that the directory is not necessarily C:\Users\[username]\.ssh. It is the directory in which you created your public key in.

For instance my home directory in Windows was changed to C:\[username]. Your home directory in a .ssh sub-folder is the best and most likely place you may have created your keys. You can check your home directory in Windows with the command:

    echo %HOMEPATH%

If you want to use "sudo", example:

sudo git clone [email protected] -o heroku

you should also generate ssh key for your root user.

sudo su
cd /root/.ssh  
ssh-keygen -t rsa
heroku keys:add

and it'll work.

if you don't use root user, generate ssh key in your user directory instead.

cd /home/user/.ssh

Sorry if my sentences messed up...

If you've already uploaded the key then try to remove the key and then re-upload it with a new key.

 heroku keys:remove //removes the existing key
 ssh-keygen -t rsa //generates a new key in ~/.ssh folder
 heroku keys:add    //uploads the new key, if no arguments r passed then the key generated                              
                    //in default directroy i.e., ~/.ssh/id_rsa is uploaded
 git push heroku

this should work.

On Windows 7,64 bit,the above solution (Onur Turhan's) worked for me with slight changes as below

C:\Users\MyName > heroku login

Enter email/password

C:\Users\MyName >ssh-keygen -t rsa -f id_rsa

This generated two files(id_rsa and in my c:\Users\MyName directory (Not in .ssh directory)

heroku keys:add
git clone [email protected]:some-heiku-xxxx.git -o heroku

I guess adding the correct "" file is the most important.After generating the public key using keygen just verify that you are adding correct key by looking at the time-stamp when it was created.

One single command works:

heroku keys:add

It will make one if it doesn't exist.

Sequence to follow

$ heroku login
$ ssh-keygen -t rsa
$ heroku keys:add

When executing second statement it would ask for input, just press Enter(return) three times and a key will be added.

Solution of dmajkic help me at last:

For Windows users it may means: git client coudn’t find your keys. Check keys in c:\Users\UserName.ssh\ and! environment variable HOME=c:\Users\UserName\

The problem I faced was on Windows and invariably whenever I run the "heroku keys:add" it selected the github keys. So here are the steps I followed to resolve the issue

  1. went to the .ssh directory under "Document and Settings" folder and deleted the git hub keys
  2. run the command heroku keys:add

The above command asked me to generate a new keys and following was the output Could not find an existing public key. Would you like to generate one? [Yn] Y Generating new SSH public key. Uploading SSH public key C:/Documents and Settings/Admin/.ssh/ done ! The 'heroku' gem has been deprecated and replaced with the Heroku Toolbelt, download and install from

  1. rerun the command heroku keys:add

The above command will not give the following output Found existing public key: C:/Documents and Settings/Admin/.ssh/ Uploading SSH public key C:/Documents and Settings/Admin/.ssh/ done

  1. Now use the git push heroku master

for me using the above steps solved the issue and was able to deploy the application on the cloud.

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 [email protected]
ssh-dss AAAAB8NzaC...DVj3R4Ww== [email protected]

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

$ sudo vim ~/.ssh/config

Edit with this info

Port 22 
IdentitiesOnly yes 
IdentityFile ~/.ssh/ssh-dss # location and name of your private key
TCPKeepAlive yes 
User [email protected]

To share my experience :

Git (my own install) was looking for the key named 'id_rsa'.

So I tried to rename my keys to 'id_rsa' and '' and it worked.

Btw, I'm sure there is an other way to do it but I didn't look deeper yet.

Try repairing permissions in Disk Utility (Mac OS X). Helped me