2

So I had the problem where you try to push to Heroku and it says Permission denied (publickey). fatal: Could not read from remote repository. So I found this question (which describes it in greater detail) and went through the whole answer and managed to kind of solve my problem. I recommend other people reading this read the next paragraph to understand my particular problem, then go try the solutions at the above link before proceeding here.

But I'm still not completely set. Here's the thing. Although I don't use it, I have the GitHub GUI installed, and if I right click a local repo in the GUI explorer and choose "Open Shell Here", whatever the context/environment of that shell is, I can push to Heroku from there no problem.

But if I just open the good ol' command line and navigate to the app folder and try the same thing, I get the whole Permission Denied your public keys sucks thing.

What could be the difference in terminal configuration??

EDIT:

It would SEEM that the above command is failing because ssh isn't working properly for some reason. When I run ssh-add -l, I get Could not connect to authentication agent, another popular error with many suggested solutions. The only one I've found (out of 10+) that works at all is to run bash (we're in Windows command prompt, mind you), then eval "$(ssh-agent)", which says Agent pid 48532, whatever that means, after which ssh-add -l says The agent has no identities, whatever that means, which is what I'm about to go research. The rabbit hole goes deeper....

Also, if I then exit bash, ssh-add -l goes right back to Could not connect to authentication agent. :( I want this to work in my normal command prompt!!

Community
  • 1
  • 1
temporary_user_name
  • 30,801
  • 41
  • 120
  • 186
  • Do you have more than 1 public key? I know that GitHub for Windows will make one automatically called `github_rsa.pub` or something like that, but by default, ssh key generation creates a key called `id_rsa.pub`. If you have more than one, which one have you added to heroku? By default, `id_rsa.pub` will be used by ssh tools, unless you explicitly pass the path of a different public key. –  Aug 07 '13 at 01:21
  • During the arduous process of learning my way around the jungle of creating, storing, and lining up SSH keys, I reduced everything to a single universal key. – temporary_user_name Aug 07 '13 at 01:24
  • Please explain what kind of shells you are using, along with the location of your home directory, and whether or not your private key is encrypted with a passphrase. –  Aug 07 '13 at 01:47
  • 1
    You may have a key defined for github in ~/.ssh/config or /etc/ssh/config. See my answer to http://stackoverflow.com/questions/18101701/ssh-permission-denied-cannot-authenticate-gitgithub-com-via-cmd – naomi Aug 07 '13 at 13:39
  • I'm using the Windows Command Prompt, which does not allow me to push to heroku, UNLESS I start it from the GitHub for Windows explorer, in which case it does. I can't figure out what the difference is between the terminal I open from windows explorer and the one I open from the GitHub explorer. Home directory is C drive, I do not believe the private key is encrypted. – temporary_user_name Aug 08 '13 at 02:49
  • Wait, define home directory. I suppose it's C:\Users\Me, but the app is at C:\Sites\app. Although, again, it works fine so long as I initiate the terminal from GitHub. – temporary_user_name Aug 08 '13 at 02:54
  • @naomi Sorry but that answer did not help. Thanks anyway. – temporary_user_name Aug 08 '13 at 02:56
  • @Aerovistae is there any reason why you don't want to just use the shell that GitHub for Windows makes available? You can tell it to use a different shell if you don't like Powershell. Personally, I don't even bother with a GUI like GitHub for Windows (I actually hate it), I just use msysgit Bash, and sometimes Cygwin mintty. –  Aug 10 '13 at 00:16
  • Also, have you tried anything from [git push heroku master Permission denied (publickey). fatal: The remote end hung up unexpectedly](http://stackoverflow.com/questions/12206779/git-push-heroku-master-permission-denied-publickey-fatal-the-remote-end-hung)? –  Aug 10 '13 at 00:18
  • I'm just trying to understand. It has nothing to do with the type of shell, it's just a normal Windows command prompt being opened by GitHub. It's that I don't like being dependent on the GitHub GUI to interact with Heroku. I should be able to access it normally. And yes, as noted and linked to in my original question above, I tried everything in that question twice. – temporary_user_name Aug 10 '13 at 00:41

2 Answers2

1

Disclaimer: I have virtually no idea what I'm talking about.

So I discovered that I was getting the Permission denied (publickey) fatal: Could not read from remote repository message because ssh-agent wasn't working properly. When I tried doing ssh-add -l, it would say Could not connect to authentication agent. Once I entered bash and did eval "($ssh-agent)", then ssh-add -l, it would say The agent has no identities, which sounds like something out of an awesome spy movie, but is in fact just an irritating hindrance to me getting work done.

I really have only a faint idea of what any of this does or means, but this is how I fixed it. Remember this is all being done in a standard Windows 7 command prompt. Assuming you're not in the bash already--

cd path-to-Git/bin (for example, cd C:\Program Files\Git\bin)
bash
exec ssh-agent bash
ssh-add "path/to/.ssh/id_rsa"

Make sure that path leads to THE PRIVATE KEY. The path must be in quotes. Do not add ".pub" at the end. You'll know it works because it'll give you a message about an identity being created or something like that.

The only thing left that still bamboozles me is wondering how I got bash installed in the first place...maybe it came with git? Or GitHub? Or Rails? Or Heroku?? Really no idea where that came from....surely it wasn't there before, I didn't think that came with Windows 7...

Anyway, after I did all this, git push heroku master worked for me in all shells, in and out of bash, even after closing and reopening. Whatever I did, it's permanent and works! Happy for now.

temporary_user_name
  • 30,801
  • 41
  • 120
  • 186
  • BY THE WAY-- this whole solution is only to make it work in a particular terminal. If you're getting that problem in general across all shell instances, you need to run through other solutions first, as shown in the link my original question-- you're probably dealing with a different problem than I was. – temporary_user_name Aug 11 '13 at 06:27
  • So it turns out your private key was encrypted after all? You can check by just opening up the key in an editor, it should tell you in plaintext whether it's encrypted or not. –  Aug 12 '13 at 05:52
  • Uhh I don't think so, I didn't have to enter a password for it...somehow ssh just wasn't set up right. – temporary_user_name Aug 12 '13 at 14:07
0

You need to check what %HOME% is in both comand-line environment.

In the "good ol' command line", you can type:

set HOME

That will display its value.

But if it isn't defined, then your error message is normal.

Type:

set HOME=%USERPROFILE%

And check the %PATH% (in order to benefit from the same commands in both environments).

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • The %HOME% values are identical, but the %PATH% values are quite different...which confuses me. %PATH% has never been something I've had a great grasp on. It looks like there's...a little?...overlap between the two different %PATHS%. How do I know what I need to make this work? I don't want to ruin the "gool ol'" %PATH% inadvertently. – temporary_user_name Aug 09 '13 at 21:49
  • @Aerovistae simply set the PATH to the same PATH as the shell which is working: `set PATH=...`, and see if that changes anything. – VonC Aug 09 '13 at 22:19
  • Although I then went and took everything that was missing from one PATH and added it to the other, and I still get the Permission denied message. – temporary_user_name Aug 09 '13 at 22:45
  • @Aerovistae in the classic shell (not GitHub for Windows), does git work? Is `git --version` recognized? In short, do you have msysgit installed? – VonC Aug 10 '13 at 11:01
  • Yes, returns `git version 1.8.3.msysgit.01`. Nevertheless, a `push` attempt on heroku yields `Permission denied (publickey). fatal: Could not read from remote repository.` – temporary_user_name Aug 10 '13 at 17:35
  • Addition data: `ssh-add -l` yields `Could not open a connection to your authentication agent` whereas in the GitHub terminal it lists my key. Certainly this must be related... – temporary_user_name Aug 10 '13 at 17:41
  • 1
    @Aerovistae regarding your last error message, that means ssh-agent isn't running: http://stackoverflow.com/q/3454774/6309 or http://stackoverflow.com/a/10077302/6309. Also http://stackoverflow.com/a/16569895/6309 – VonC Aug 10 '13 at 18:28
  • I FIXED IT, OH MY GOD THIS IS SATISFYING.....but....if I write in an answer, who gets the bounty?? – temporary_user_name Aug 11 '13 at 02:27
  • @Aerovistae well... considering I give you clues leading to the ssh-agent issue, you can still select my answer ;) – VonC Aug 12 '13 at 15:03
  • A drop in the ocean for you. Why not? – temporary_user_name Aug 12 '13 at 15:19
  • @Aerovistae thank you. That is one ocean built drop after drop for 5 years every single day: http://meta.stackexchange.com/q/122976/6309 – VonC Aug 12 '13 at 15:37
  • Couldn't hurt for you to +1 my answer and question to contribute to my ocean :) – temporary_user_name Aug 12 '13 at 18:50
  • @Aerovistae I cannot +1 your answer... because I already did, minutes after you wrote it. And Stack Overflow won't let me upvote an answer twice. – VonC Aug 12 '13 at 20:42
  • @Aero you asked me if I could +1 your answer. I answered that I already did +1 your answer. – VonC Aug 13 '13 at 03:50
  • I'm sorry, I was just kidding, guess it was too subtle. – temporary_user_name Aug 13 '13 at 05:41