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

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.

This question is related to git heroku deployment public-key

The answer is


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

  • Open terminal and type in defaults write com.apple.Finder 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/id_dsa.pub

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


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

->heroku login

[email protected] & 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 [email protected]: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 was the solution for me:

ssh-add ~/.ssh/my_heroku_key_rsa

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 was experiencing the same problem; following these steps should help:

  1. First, log in: heroku login
  2. Clear all keys: heroku keys:clear
  3. Delete all files in local folder ( all .pub files and know_host) in .ssh/ folder
  4. Log in again : heroku login - u will prompt with no key, so follow the onscreen instructions.

I reinstalled heroku toolbelt and it worked.


It sounds like your ~/.ssh/authorized_keys file is not set up correctly. Verify that:

  • It is in the correct path.
  • The permissions of the file are 0600.
  • The permissions of ~/.ssh are 0700.

If you are a windows user the other solutions here probably won't solve your problem.

I use Windows 7 64-Bit + Git-1.7.7.1-preview20111027 and the solution was to copy my keys from C:\users\user\.ssh to C:\Program Files (x86)\Git\.ssh. That's where this git client looks for the keys when pushing to heroku.

I hope this helps.


For all those who tried everything mentioned above on Windows 7 and still it didn't work, here is what I've done: - open GitBash.exe from the Git directory C:\Program Files (x86)\Git\ (don't open a command prompt, this won't work). - add the following as mentioned above, but you have to delete the #

Host heroku.com
Hostname heroku.com 
Port 22 
IdentitiesOnly yes 
IdentityFile ~/.ssh/ssh-dss
TCPKeepAlive yes 
User [email protected]

now run git push heroku master and it should work.


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.


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

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]

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"

not

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

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/my_ssh.pub' are too open.

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

sudo su

password


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.


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


Pushing was working for me and then stopped suddenly.

If the heroku api is experiencing downtime, you will get this error when you try to push.

Check:

https://status.heroku.com/

before freaking out too hard.


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\


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 id_rsa.pub) in my c:\Users\MyName directory (Not in .ssh directory)

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

I guess adding the correct "id_rsa.pub" 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.


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 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"

to

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

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


when pushing using

git push heroku production:master 

your public key under home directory ~/.ssh/id_rsa is used

To fix this

you should login as a different user may be root

sudo su 

then start fresh by issuing the following commands

heroku keys:clear //removes existing keys
ssh-keygen -t rsa //generates a new key in ~/.ssh folder (set a password)
heroku keys:add   //uploads the new key, ~/.ssh/id_rsa is uploaded                      
git push heroku production:master

Instead of dealing with SSH keys, you can also try Heroku's new beta HTTP Git support. It just uses your API token and runs on port 443, so no SSH keys or port 22 to mess with.

To use HTTP Git, first make sure Toolbelt is updated and that your credentials are current:

$ heroku update
$ heroku login

(this is important because Heroku HTTP Git authenticates in a slightly different way than the rest of Toolbelt)

During the beta, you get HTTP by passing the --http-git flag to the relevant heroku apps:create, heroku git:clone and heroku git:remote commands. To create a new app and have it be configured with a HTTP Git remote, run this:

$ heroku apps:create --http-git

To change an existing app from SSH to HTTP Git, simply run this command from the app’s directory on your machine:

$ heroku git:remote --http-git
Git remote heroku updated

Check out the Dev Center documentation for details on how set up HTTP Git for Heroku.


The above given answer DOES work, but found out I needed to do some extra steps before it worked.

  1. I removed all id_rsa* files and generated a new SSH using this guide.
  2. Then, I destroyed the heroku app. Removed the ~/.heroku/credentials file.
  3. 'heroku create' command (and since the credentials file is removed, it will prompt you for your email/password.
  4. FINALLY type 'heroku keys:add' and it will upload the default ~/.ssh/id_rsa.pub file.
  5. It works! Well.... YMMV but I really do hope this can be some help as I struggled the whole day trying to figure this out! Haha

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!


If the other answers didn't worked for you. Try this!

Sometimes all you need is to push again. It happen to me today due to slow internet connection(when you are downloading or using p2p).

Please see screenshot below:

enter image description here


I had to do:

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

Then it worked:

$ git push heroku master  

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 id_rsa.pub

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...


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


One single command works:

heroku keys:add

It will make one if it doesn't exist.


Here is the link that explains how to manage your ssh keys: https://devcenter.heroku.com/articles/keys#adding-keys-to-heroku


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 'id_rsa.pub' and it worked.

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


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/id_rsa.pub... done ! The 'heroku' gem has been deprecated and replaced with the Heroku Toolbelt, download and install from https://toolbelt.heroku.com.

  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/id_rsa.pub Uploading SSH public key C:/Documents and Settings/Admin/.ssh/id_rsa.pub... 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.


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to heroku

How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip Can't push to the heroku ImproperlyConfigured: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings How to enable CORS in flask Error: Cannot pull with rebase: You have unstaged changes How to solve error "Missing `secret_key_base` for 'production' environment" (Rails 4.1) Failed to execute 'postMessage' on 'DOMWindow': The target origin provided does not match the recipient window's origin ('null') 'heroku' does not appear to be a git repository Heroku 'Permission denied (publickey) fatal: Could not read from remote repository' woes How do I set up DNS for an apex domain (no www) pointing to a Heroku app?

Examples related to deployment

error: This is probably not a problem with npm. There is likely additional logging output above Deploying Maven project throws java.util.zip.ZipException: invalid LOC header (bad signature) repository element was not specified in the POM inside distributionManagement element or in -DaltDep loymentRepository=id::layout::url parameter "Untrusted App Developer" message when installing enterprise iOS Application How do I copy directories recursively with gulp? How to deploy correctly when using Composer's develop / production switch? Enterprise app deployment doesn't work on iOS 7.1 Can not deserialize instance of java.lang.String out of START_OBJECT token Run command on the Ansible host Error when deploying an artifact in Nexus

Examples related to public-key

key_load_public: invalid format Verify host key with pysftp Github permission denied: ssh add agent has no identities git push: permission denied (public key) Heroku 'Permission denied (publickey) fatal: Could not read from remote repository' woes Using scp to copy a file to Amazon EC2 instance? How to ssh connect through python Paramiko with ppk public key Adding a public key to ~/.ssh/authorized_keys does not log me in automatically Permission denied (publickey) when deploying heroku code. fatal: The remote end hung up unexpectedly GitHub: Permission denied (publickey). fatal: The remote end hung up unexpectedly