Heroku – Trouble with Windows and SSH Keys

Heroku, one of my favorite cloud platforms, is a hosted platform built specifically for deploying Rails and other Ruby based web applications. Heroku makes deploying Rails applications to cloud ridiculously easy – as long as your source code is under version control with Git.

The general process of installing and using Heroku on Windows is fairly simple. You should already have Ruby, Rails and Git for Windows (msysgit) installed. Once you have them, go to Heroku.com and sign up for an account. After signing up, install the Heroku gem with the following command.

$ gem install heroku

Typically, as in GitHub you will need to create SSH keys if you haven’t already, and then tell Heroku about your public key so that you can use Git to push your application repository up to their servers. Detailed information for setting up Git and creating ssh keys on Windows can be found here.

# Create new keys
$ ssh-keygen -t rsa -C "your_email@yourdomain.com"

# Tell heroku about your public key
$ heroku keys:add

Remember? Your source code should be under version control with git. So, from within the root of your application folder, use typical git gimmicks to create a local git repository and commit your application source to the local repository.

$ cd my_app
$ git init
$ git add .
$ git commit -m "initial version"

Finally, from within the root of your application folder, use the heroku command to create a place on the Heroku servers for the application to live. Then, you can deploy your application to the cloud by pushing your local git repo to heroku…

# Create an application space on the server
$ heroku create

# Deploy your application to the cloud
$ git push heroku master

If until now everything went well except for the last step and instead of getting your application deployed if you got the following error, then it was worth your time to have read this post until this point…

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

It was a frustrating experience trying to figure out the problem. The keys were created fine and they got added to heroku just fine as well. In fact i could verify it with the following command and my keys were right there.

heroku keys:list

Whatever I do, I kept getting the same error. Finally after a lot of googling, experimenting and hair plucking the problem got resolved. Here goes the solution…

Solution:
Typically once you create the keys as mentioned above, two files – “id_rsa” and “id_rsa.pub” – are stored in the “.ssh” folder within the user’s home folder. If you are working with linux that seems to be good enough. But for the windows version of git that doesn’t seem to cut it. It wants the keys to be stored inside the “.ssh” folder within the “msysgit” installation folder as well. If you don’t find a “.ssh” folder inside the “msysgit” installation folder, feel free to create one. Once you drop these two key files there and repeat the entire process, everything went as smooth and my application got deployed in the heroku cloud and the world is again a better place to live in.

I am sure many people will hit the same road block. At least I am sure I will come across it again and wouldn’t remember how I solved it in the first place. Happens, doesn’t it? So, I thought i will document it here for future reference.

If there is any other solution, or if this solution is incorrect, feel free to leave a comment.

Ganeshji Marwaha

I spend my days as the Director of Technology for Mobility practice and help my clients design enterprise and consumer mobile strategies. Mobile Payments, Digital Wallet and Tokenization technologies are my areas of specialization

  • Thomas Deml

    Copying id_rsa and id_rsa.pub to C:\Program Files (x86)\Git\.ssh did the trick for me. Thanks for the hint!

  • Carey Hazelton

    Added a couple useful features to this great lightweight carousel. More often than not this is all you need. jCarousel is great but most of the time it is far more than you need IMO. Anyway I extended this great work just a hair to include another options that I feel is needed. That is to return to the first slide on end rather than circular. If circular = false then you can enable the new option which is onEndFirst = true This will simply return to the first slide after the length has been met. If circular is false and onEndFirst is false it simply stops the carousel like the original code did. You can grab the min version at http://www.origin1.com/downloads/samplecode/jcarousellite.1.0.1.min.custom.js Oh added some simple paging too with some nice selectors that overlay. I’ll post a sample page here once I light it up and you can just look at the source…cheers.

  • Faisal

    Instead of generating the key using Git I had to generate it using cygwin. Then I placed it Git folder and it worked. I think ssh.exe in Git was not working for me.

  • Thanks Thomas ๐Ÿ™‚
    That did it for me

  • god bless you!
    i was having problem while cloning my code.

  • Moustafa Samir

    Thanks Thomas
    It worked for me now

  • Oz

    Thanks a lot
    did the trick for me as well

  • Marco

    It works for me !!! Thanks a lot I was searching a solution for a long time !

  • THANK YOU! another reason I hate windows… lol… thank you so much!

  • Magda

    Thank you! You save my life (or at least my nerves ;)) Only your solution helped me (in my case it was “c:\Program Files (x86)\Git\.ssh\” not “msysgit” but it wasn’t hard to find the proper directory ๐Ÿ™‚ ). Thanks a lot again!

  • Joseph

    Please, how can i get your tuto about it “Build a Real-Time collaboration application with Node.js, Express.js, Socket.io, HTML5, CSS3 & Websockets” Thanks!

  • CKNY

    I think I really get crazy with this “fatal: the remote end hung up unexpectedly” issue. I copied the keys to the .ssh folder in C:\Program Files (x86)\Git. I verified the keys: heroku keys, but I actually see 3 keys that I created. Not sure whether this is an issue. I really feel like windows and git/heroku are no match in heaven. Any new debugging ideas?

  • Brilliant tutorial! I truly impressed to read about Heroku is also my favorite platform. Thanks for solve the trouble! ๐Ÿ™‚

  • Brilliant tutorial! I truly impressed to read about Heroku is also my favorite platform. Thanks for solve the trouble! ๐Ÿ™‚

  • I had to produce it using cygwin. Then I placed it Git directory and it proved helpful. I think ssh.exe in Git was not operating for me.Vinyl Sticker Printing

  • u r awesome

    good one man. thanks

  • Air Yeezy 2 and great customer service. If you have any problem with our products, please contact us in time, pleas give us a chance to help you to solve the issue. Wish you a happy shopping experience.

  • Drake

    The public key is stored on the Linux/UNIX bartender and the private key is stored on your local Windows computer.
    seo Newcastle upon Tyne

  • am on windows 7 and I have railsinstaller installed which incldues the GIT package.
    I have copied the key files as aper your instrcution to my GIT folder D:\RailsInstaller\Git and still having the same issue..

    But I know I got an issue with my Windows Firewall. It is always off and the services does not start. Like if Windows Firewall is corrupted. I tried everything to solve the firewall issue, but the only solution seems to be restoring my pc to factory settings to get the firewall working. But can a corrupted firewall causes this issue? Git pushing is working . it is only Heroku exactly like in your case.