'ssh-keygen' is not recognized as an internal or external command
Asked Answered
E

14

110

I run git push -u origin master

It tells me that "Permission denied (public key) fatal: The remote end hung up unexpectedly"

Then I looked up on the internet and found that I had to generate an ssh key for my account on GitHub. However, upon doing so, when I tried to do ssh-keygen -t rsa "[email protected]" it simply said ssh-keygen is not recognized. I tried doing mkdir C:\ssh but that didn't work. If it helps I'm using Ruby Rails and I'm on a Windows computer. Could anyone help me?

Epicedium answered 2/8, 2012 at 5:10 Comment(0)
G
136

2012:
ssh-keygen.exe is part of msysgit:

 C:\path\to\msysgit1.7.11\bin\ssh-keygen.exe

if your %PATH% includes C:\path\to\msysgit1.7.11\bin\, you will have ssh-keygen.


Update 2015:
ssh-keygen.exe is part of Git For Windows, whose releases include PortableGit-2.4.3.1-2nd-release-candidate-64-bit.7z

c:\path\to\PortableGit-2.4.3.1-2nd-release-candidate-64-bit\usr\bin\ssh-keygen.exe

That means the %PATH% must include c:\path\to\PortableGit-2.4.3.1-2nd-release-candidate-64-bit\usr\bin (without the ssh-keygen.exe)

As I explained before, Git for Windows will soon phase out msysgit.
I detailed in "Why is it that if you download Git 2.0 from the net, you always get a 1.9.4 installer package?" how this new version is based on the more recent msys2 project.

Ghyll answered 2/8, 2012 at 6:7 Comment(6)
Is it safe to have ssh-keygen.exe in the PATH on Windows? Do I need to remove its location after that?Knickknack
@Knickknack actually, it is part of the Windows PATH only during your session with git, since you are launching a special DOS session with git-cmd.bat: github.com/msysgit/msysgit/blob/master/git-cmd.bat. It will complete the PATH and set HOME.Ghyll
Acutally, the path should be without ssh-keygen.exe. I mean, it works only in this way for me.Torrlow
@Torrlow I agree, and I have edited the answer to make that more visible.Ghyll
for me, path was C:\Program Files (x86)\Git\usr\binCobble
@rupinderjeet47 Yes, it is <wherever git is installed\usr\bin>. I prefer using the archives unzipped where I want rather than the msi setup which installs by default in C:\Program files\Git.Ghyll
T
65

I just had this issue and thought I'd share what I thought was an easier way around this.

Open git-bash and run the same command with the addition of -C since you're commenting in your email address: ssh-keygen -t rsa -C "[email protected]" command. That's it.

git-bash should have been installed when you installed git. If you can't find it you can check C:\Program Files\Git\Git Bash

The first time I did this it failed to create the .ssh folder for me so I had to open a standard Command Prompt and mkdir C:\Users\yourusername\.ssh

Triquetrous answered 10/5, 2013 at 22:30 Comment(4)
+1 for not suggesting installation of another software packageOctahedral
+1 this is a better solution becuase do not need other installationAngara
My key didn't saved in .ssh folder. It was saved in the same directory as Git Bash exists.Disruption
In my case neither ssh-keygen nor ssh is found in powershell. Sessions before however it worked.Chalcocite
M
53

I followed below in windows (With Git for Windows installed)

  1. Run "Git Gui" (Start --> Git --> Git Gui)
  2. Click Help and then Show SSH Key
  3. Click Generate Key if you do not have one already

Note:- this creates the key files under your personal profile folder C:\Users\YourUserID\.ssh\

enter image description here

Micropathology answered 14/6, 2017 at 16:11 Comment(1)
Great answer - a nice easy way to create a new SSH-key - TY :)Hypogastrium
W
10

No need to add anything to environmental variables! Just open up git bash and perform command the ssh-keygen in there.

Link to download git bash here

Whistle answered 28/7, 2014 at 12:7 Comment(0)
B
9

I found an easy solution to fix this :

In the command prompt, go to your git\bin directory, and then execute your commands from here

Barnabas answered 10/4, 2014 at 16:50 Comment(1)
On my system, Windows 10, ssh-keygen.exe was found in 'git\usr\bin'.Agouti
G
8

If you have installed Git, and is installed at C:\Program Files, follow as below

  1. Go to "C:\Program Files\Git"
  2. Run git-bash.exe, this opens a new window
  3. In the new bash window, run "ssh-keygen -t rsa -C""
  4. It prompts for file in which to save key, dont input any value - just press enter
  5. Same for passphrase (twice), just press enter
  6. id_rsa and id_rsa.pub will be generated in your home folder under .ssh
Gilud answered 8/9, 2017 at 16:21 Comment(0)
V
4

Just go to heroku.bat and add:

@SET PATH="D:\Program Files (x86)\Git\bin";%PATH% after @SET PATH=%HEROKU_RUBY%;%PATH%

in my case it's in D:\Program Files (x86)\Git\bin, change it to the path you've installed Git to. (i just left it with my path so it will be clearer on how to write this)

Valance answered 18/12, 2013 at 11:46 Comment(0)
J
3

I think you can add the location of the file ssh-keygen.exe in the PATH environment variable. Follow the steps: Go to My Computer->Right click->Properties->Advanced System Settings->Click Environmental Variables. Now click PATH and then click EDIT. In the variable value field, go to the end and append ';C:\path\to\msysgit1.7.11\bin\ssh-keygen.exe' (without quotes)

Jeconiah answered 30/10, 2012 at 13:47 Comment(0)
S
3

don't do anything just type in your command prompt

C:\> sh

then you got like this

sh-4.4$ 
# type here 
ssh-4.4$ ssh-keygen -t rsa -b 4096 -C "[email protected]"

this should must work.

Soong answered 7/11, 2017 at 6:26 Comment(0)
C
3

For windows you can add this:

SET PATH="C:\Program Files\Git\usr\bin";%PATH%
Ceraceous answered 31/10, 2018 at 5:24 Comment(0)
S
1

You probably should check this. Windows doesn't have that command built in.

Seigneur answered 2/8, 2012 at 5:12 Comment(0)
B
0

I got it fixed by just adding ssh-keygen to my environment variables.

Belldas answered 10/6, 2013 at 7:52 Comment(1)
What exactly did you do?Tweeze
L
0

for those who does not choose BASH HERE option. type sh in cmd then they should have ssh-keygen.exe accessible

Lesser answered 17/11, 2016 at 20:25 Comment(0)
I
0

In my machine, ssh-keygen was available from powershell.

Isolde answered 1/4, 2019 at 17:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.