85

Please excuse a bit of frustration, which I will try to keep in check since Heroku is using SO as their customer support (which I think it shoddy to say the least).

For the last five hours I have been trying to get an application to publish, but invariably something goes wrong with the keys. I've read dozens of articles and tried tip after tip in an effort to figure out where, in the stupid, completely opaque process Heroku is screwing up.

My use case is not that difficult: I have created a new keypair for my heroku apps. I have set that key to be my key:

  > heroku keys
  === travis@xxxx.com Keys
  ssh-rsa AAAAB3NzaC...avOqfA7ZBd travis@xxxx.com

I can log in and "create" an application (stupid name, since it seems to be creating a git repo, not any sort of app) without problem. But every *freaking* time I try to push my app, I get:

  > git push heroku master
  Permission denied (publickey).
  fatal: The remote end hung up unexpectedly

I have no insight into WTF is going on with it; I'm just stuck banging my head against a keyboard with no recourse but to hope the almighty god of Google can answer it. And google isn't answering it (well, let me take that back, I've seen about a dozen ways to answer this).

For a system that is supposed to be easy, this is a joke. I like the idea of Heroku, but after taking five our to get absolutely nothing done, I'm thinking maybe it is the wrong choice.

Travis Jensen
  • 5,362
  • 3
  • 36
  • 40
  • 7
    I'll have you know that the customer support we provide for Heroku is first-class shoddy. – Robert Harvey Aug 30 '12 at 23:01
  • 1
    I've never been anything but impressed by the quality of answers at SO. I just think it is a lame way to provide customer support for a product, no matter how technical. What happens if I have to provide personal account details? Not exactly what I want to share with the world (as I realized when I needed to modify the original post). – Travis Jensen Aug 30 '12 at 23:04
  • You did see [this question](http://stackoverflow.com/q/3617113/62576)? Especially the part about registering your public key with git? – Ken White Aug 30 '12 at 23:29
  • 7
    Same issue, got the solution here: [http://www.whatibroke.com/?p=284](http://www.whatibroke.com/?p=284) –  Nov 12 '12 at 22:19
  • 1
    Remi's linked solution worked for me. – Deborah Jan 13 '13 at 09:23
  • I love the frustration in this question - I have been there so many times. I can't remember what it was like without SO (and I don't want to). – Damien Del Russo Apr 08 '13 at 00:22
  • @Travis is right. No matter how excellent the customer service is, it shouldn't be like this. As a user-experience type, with a long software development background, I know what I'm saying. We developers, when thinking as developers (wearing dev's hats), are not entitled to design UI interactions. Think of this case: the user (Travis, now me) receives a message telling that something went wrong but there are no clues on how to move on. Of course to the guy who developed this the message is crystal clear because of his background, which is quite unique. – Juan Lanus Jul 10 '13 at 17:28
  • Moreover, this is a "frequently asked question", according to the votes and views (9K+!). When a question is asked many times, the owners of the UI must ask themselves what's going on in that spot. It's OK to post an answer, but the real solution is to fix the interaction bits that are throwing that many people out. Pls talk with a user interaction guy, seek advice, have more and happier customers, earn more money, enter a win-win trade. – Juan Lanus Jul 10 '13 at 17:34

6 Answers6

149

There are a variety of solutions around the web. I will try to condense the available options into one post. Please try your connection again after every step.

  • Step 1: Attempt adding you public key to Heroku

    heroku keys:add ~/.ssh/id_rsa.pub // or just heroku keys:add and it will prompt you to pick one of your keys
    
  • Step 2: Generate a new set of SSH keys, then attempt the first step again

    https://help.github.com/articles/generating-ssh-keys

  • Step 3: Verify and/or modify your config file

    vim ~/.ssh/config
    
    Host heroku.com
    Hostname heroku.com 
    Port 22 
    IdentitiesOnly yes 
    IdentityFile ~/.ssh/id_rsa    <--- Should be your public SSH key
    TCPKeepAlive yes 
    User jsmith@gmail.com
    
  • Step 4: Remove the heroku remote from git, the recreate the connection, adding the remote via heroku create will only be an option for new repositories. Be sure to delete your old repo that you originally attempted to create

     $ git remote rm heroku
     $ heroku create
    
  • Step 5: Reinstall Heroku Toolkit

geoyws
  • 3,326
  • 3
  • 35
  • 47
jquintana
  • 1,559
  • 1
  • 10
  • 6
  • 10
    Step 1 did the trick for me! (I did recreated my SSH keys for my machine and Github before pushing them to Heroku however.) Thanks! – ATSiem May 18 '13 at 19:02
  • 1
    NONE of this worked for me, despite very carefully doing it from the top twice with clean installs and everything. In the end the thing that made it all work was to make sure my GitHub key and the Heroku key were the same. I don't even understand why that made a difference, unless I somehow failed to notice that Heroku relies on GitHub, but somehow it fixed the problem. Keys can be changed in account settings on GitHub. I think you ought to add this into your answer. – temporary_user_name Aug 07 '13 at 00:48
  • This doesn't address the issue and won't work for everyone. Please see the answer below. Simply put, the keys are out of sync. – Robert Christian Aug 07 '13 at 06:18
  • 1
    I believe that the IdentityFile line should be your private ssh key. See http://stackoverflow.com/a/8874946/2816571 – Paul Oct 18 '13 at 02:12
  • thanks. apparently `heroku login` had not sent my pub key to heroku, hence the issue. – njzk2 Jan 21 '14 at 13:50
  • 2
    Did you mean `heroku create`? `git heroku create` is not a thing, so far as I know. – Michael Dorst Jan 31 '14 at 11:30
  • 1
    Wow. I can't think of anything pleasant to say about this experience. I followed numerous recipes, including uninstalling/reinstalling git, github and replacing putty with msysgit. Step 1-3 finally did it, but the change needed to be in the github ssh_config. After dropping and resetting my github keys several times without any issues, the heroku process was *really* frustrating. – wilk Feb 28 '14 at 19:27
  • 1
    What's the reason for re-installing the toolkit? – Jonathan May 25 '14 at 02:11
13

Your heroku key and github keys are not in sync.

  • Determine which key you want to use (recommend creating a new one ie heroku_rsa).

  • Add the key to github.

  • Add the same key to heroku using: heroku keys:add

Robert Christian
  • 18,218
  • 20
  • 74
  • 89
  • 4
    I *really, really, really* wish I had read this answer four hours ago. Although I supposed I learned a lot along the way, so, not all bad. – temporary_user_name Aug 07 '13 at 00:50
  • I have two different Heroku accounts (one using my work email, for projects at work, the other using my personal email, for freelance projects). Heroku won't let me use the same key for both. So how can I use my Github key for both? (And why does Heroku specifically need to use my Github key anyway? What has Heroku got to do with Github? What if I didn't use Github?) I'm so confused – callum Oct 25 '13 at 10:55
  • Worked like a charm! Thanks! – Shashank Sep 20 '17 at 06:53
2

I've encountered the same issue, and this is my theory as to what's going on:

I signed up for Heroku a long time ago, giving them my github public key. When attempting the usual git push heroku master, it goes and looks for my private key, found at ~/.ssh/github_rsa. It then fails silently with the message you posted.

However, I tried later to ssh into another server using the -i flag to specify my "identity file" (i.e. private key), and it prompted me for the password to my private key. Having "unlocked" the private key, the git push heroku master command works. Some conclusions:

  • While ssh will prompt you for the password to an identity file, git will not.
  • If you unlock the identity file with another method, like ssh, it will stay unlocked for your git usage.
  • There doesn't seem to be any documentation on how to permanently remove the password protection on an identity file, including with the common unix command keytool.
  • Above solutions of creating a new public/private key pair seem to be a workaround for this password issue, without knowing that's the problem.
owensmartin
  • 393
  • 4
  • 11
2

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

I think this might have your solution, it did for me at least

Community
  • 1
  • 1
Cabbibo
  • 1,371
  • 3
  • 17
  • 30
1

With me, it seemed the problem was that I had ssh-agent running in the background, and the relevant private key had not been added to it.

ps -afe | grep ssh-agent

ssh-add ~/.ssh/id_rsa_heroku_github

I also had to add the public key to github (manually) and heroku

heroku keys:add ~/.ssh/id_rsa_heroku_github.pub
cobberboy
  • 5,598
  • 2
  • 25
  • 22
0

If none of the other solutions work for you, be sure that you are logged in linux shell with your account and not with root account.

That way, if you are running with the user that is not the owner of your ssh keys, git will look for the wrong keys to authenticate

Saulo Falcao
  • 321
  • 2
  • 3