Could not generate ssh public key for heroku in Windows 7
Asked Answered
O

4

31

While I am trying heroku login through cmd in my machine, it says

Could not find existing public key
Would you like to generate one? [YN]

After that when I press 'y' and enter it says

Generating new ssh public key
Could not generate key: "ssh-keygen" is not recognized as a internal or external command operable program or batch file

Please help me.

Outgoing answered 22/2, 2013 at 6:58 Comment(2)
See this previous answer: https://mcmap.net/q/194805/-39-ssh-keygen-39-is-not-recognized-as-an-internal-or-external-commandJoshua
@user2098336 it would be very important to choose the solution that solved your troubles to help other programmers facing the same issue in the future!Dipper
A
34

Heroku toolbelt includes git distribution which includes the required ssh-keygen.exe . I've just found it in C:\Program Files\git\bin . Locate your git folder and add it to your system path as described here: superuser.com/questions/284342/

Atul answered 22/2, 2013 at 19:50 Comment(2)
As per a comment on another answer, and since this is the most upvoted (as it is correct), I'll note: if you use the git bash CLI to log into heroku using heroku auth:login, you will be able to generate an SSH key. If you use a normal cmd shell on windows with the same command, you will need to include your Git directory in your PATH; the reason for this behavior is because, as per yet another comment, Git bash sets the PATH when it is run.Ranunculaceous
in my case on Win 10 it is situated in C:\Program Files\Git\usr\bin !Loner
H
16

I had the same problem and just solved it. I installed another CMD called Git Bash that you can download for free (http://git-scm.com/downloads) and then repeated the commands in that and it worked!

Hernia answered 10/4, 2013 at 9:30 Comment(1)
I pretty sure that the heroku toolbelt includes git bash now, if not at the time of the post. But, yeah, I made the same mistake, going straight for CMD as is habit -- same error. Since I already had git bash, tried that, and it worked charmfully! Thank you.Sherfield
M
1

For Win7 64-bit users, the file %HerokuPath%s\bin\ssh-keygen.bat looks like:

@SETLOCAL
@SET HOME=%USERPROFILE%
@"%HerokuPath%\..\Git\bin\ssh-keygen.exe" %*

But Heroku installs Git in Program Files (x86), so if you update the .bat file to:

@SETLOCAL
@SET HOME=%USERPROFILE%
@"C:\Program Files (x86)\Git\bin\ssh-keygen.exe" %*

Then you should be able to generate your ssh keys.

Merkle answered 28/11, 2014 at 18:9 Comment(0)
N
0

Windows 10-64bit

I had installed git, then heroku toolbelt (which I think reinstalled git)

I had C\Program Files (x86)\Heroku\bin in my Environmental variable (probably generated when I installed heroku toolbelt) and if I looked in that filepath I had an ssh-keygen.bat - so it seemed like I should be able to just run ssh-keygen -t rsa from the command line.

That would be too easy, instead I get:

C:\Program Files (x86)\Git\bin>ssh-keygen -t rsa -f id_rsa
'"C:\Program Files (x86)\Heroku\..\Git\bin\ssh-keygen.exe"' is not recognized as an internal or external command,
operable program or batch file.

Solution

type bash in command line to go into git bash mode then run ssh-keygen -t rsa

git bash:

mamwo@DESKTOP-9GVG6K8 MINGW32 /bin
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/mamwo/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/mamwo/.ssh/id_rsa.
Your public key has been saved in /c/Users/mamwo/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:MMMYYYPPPUUUBBBLLIIICCKKEEEEYYYY mamwo@DESKTOP-9GVG6K8
The key's randomart image is:

Now when I look in C/User/mamwo/.ssh (the best way for me is through pycharms folder - windows sucks) I see my id_rsa and id_rsa.pub

But this 'cannot generate publickeys' issue all started for me because I had an 'I don't have public keys to add' issue when I cloned my repo (from github) to a new computer and found that I could push to github but not heroku.

Now that I have the keys - I have to add them

C:\Users\mamwo\Desktop\mv>git push heroku master
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

C:\Users\mamwo\Desktop\mv>heroku keys
You have no keys.

C:\Users\mamwo\Desktop\mv>heroku keys:add
Found an SSH public key at C:/Users/mamwo/.ssh/id_rsa.pub
Would you like to upload it to Heroku? [Yn]
Nissy answered 1/3, 2016 at 13:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.