Overcome Heroku’s “Permission denied publickey” problem

Heroku is awesome on paper (or screencast) but after following the directions it never worked for me. I couldn’t figure out why, and the Heroku discussion forum didn’t have any answers. But I think I’ve finally figured it out. (In the very least, I’ve finally gotten it working, which is the next best thing!)

Heroku (before today) would let me do everything except clone my remote apps to my local machine, which is more convenient, and in some cases essential (as when doing Rails apps with Hobo). Observe this:


$ heroku clone hobocookbook [/Data/Rails] [DrTeeth]
Initialized empty Git repository in /Data/Rails/hobocookbook/.git/
The authenticity of host 'heroku.com (75.101.141.116)' can't be established.
RSA key fingerprint is 8b:48:5e:67:0e:c9:16:47:32:f2:87:0c:1f:c8:60:ad.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'heroku.com,75.101.141.116' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
/usr/local/lib/ruby/gems/1.8/gems/heroku-0.3/bin/../lib/heroku/command_line.rb:37:in `clone': could not clone the app. Is git installed? (RuntimeError)
from /usr/local/lib/ruby/gems/1.8/gems/heroku-0.3/bin/../lib/heroku/command_line.rb:6:in `send'
from /usr/local/lib/ruby/gems/1.8/gems/heroku-0.3/bin/../lib/heroku/command_line.rb:6:in `execute'
from /usr/local/lib/ruby/gems/1.8/gems/heroku-0.3/bin/heroku:36
from /usr/local/bin/heroku:19:in `load'
from /usr/local/bin/heroku:19
$

If I may cut to the chase…it appears that the Heroku setup process assumes that the public key you give it will be your default or only public key, while in fact I made a key pair just for Heroku. So once I added some details to my ~/.ssh/config file:

Host heroku.com
Hostname heroku.com
Port 22
IdentitiesOnly yes
IdentityFile ~/.ssh/id_heroku
TCPKeepAlive yes
User brandon

So far as I know, this solution isn’t listed anywhere else on the web, but I found a tiphere that mentioned changing your default public key, which tipped me off as to what the problem was. (Of course now that I know the solution, I could much more effectively Google to see if anyone else has found it–one of the shortcomings of current search technology as a strategy for finding answers. The keywords you really want to use are the ones in the answer, but of course you don’t know those until you know the answer.)

Anyway, I hope this helps the legions of other people out there who would love to use Heroku but can’t because their use case was overlooked by the set up program.

Explore posts in the same categories: Rails, Ruby, Web Development

Tags: , ,

You can comment below, or link to this permanent URL from your own site.

7 Comments on “Overcome Heroku’s “Permission denied publickey” problem”

  1. zahid313 Says:

    you might want to try and copy past the both key files generated from cygwin_root\home\[username]\.ssh\ to
    [windowsdrive]\users\[username]\.ssh

    this solved for me
    i am using windows 7


  2. […] still get a ‘permission denied(publickey)’ error. After a bit of searching I came upon this article that explains […]


  3. I use msysgit for for Windows 7 64-Bit version: Git-1.7.6-preview20110708, and just got “git push heroku master” in The Ruby on Rails Tutorial working by copying my keys from “C:\Users\\.ssh” to “C:\Program Files (x86)\Git\.ssh” which was empty and aparently was where it was looking for the keys when pushing to heroku.

    Also the “know_hosts” file is different in both directories. In my user folder it has the github key and in the git install directory it has the heroku key, which was what tipped me off. I hope this helps someone. Thanks for the above comments and original post, which helped me find my solution ❤

  4. cnu Says:

    This was the solution I was searching for and this helped. Thanks.


  5. Thank your very much, excellent solution. Very helpful!


  6. This was the only way I could deploy to heroku. Thanks for posting this 😀

  7. zproxy Says:

    wow. it worked. thanks for the ad-hoc doc support 🙂 now go ask heroku some cash:D


Leave a reply to Bjarne Kristensen Cancel reply