12

I continually run into the same error when I try to generate an SSH key:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/konrad/.ssh/id_rsa):

Here I press enter.

Could not create directory '/home/konrad/.ssh'

Then I enter my passphrases.

open /home/konrad/.ssh/id_rsa failed: No such file or directory.
Saving the key failed: /home/konrad/.ssh/id_rsa.

I've tried re-installing Git multiple times, but that hasn't helped. I think it may be because C:/Users/Konrad should be the default directory, rather than /home. Any advice?

Konrad
  • 123
  • 1
  • 1
  • 4
  • 1
    Are you on windows? Are you using cygwin, or some gui installer? Try using a directory that exists for storing your keypair when it asks (so type in C:\Users\Konrad instead of accepting the default by pressing enter). – Ben Taitelbaum Jun 04 '11 at 16:35
  • Well I had to accept default, guess it was because I only typed Users and not C/Users – Warpzit Dec 23 '11 at 09:30

2 Answers2

9

On msysgit, you need first to set the user environment variable HOME (which isn't set by default in Windows).

HOME can be set to any directory you want, you only have to make sure you have the right to write in it (and that the directory exists and a .ssh under it exists too).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • strangely enough, I never had to set that env var on my setup. Either the msysgit installer did it for me waaaay back when, or it was already set - could this have been removed from the msysgit installer since git...ohh, maybe git 1.6.6-ish? – damianb Jun 04 '11 at 17:19
  • @Obsidian_: I somehow doubt that any installer would set that kind of variable for you: too much potential side-effect. On Windows, you really need to set it up yourself. – VonC Jun 04 '11 at 17:58
  • How do you set the HOME variable? Mine seems to be set to "/h", which might be problem why I get the same error as OP. – user1809923 Jan 20 '15 at 09:28
  • @user1809923 http://superuser.com/q/25037/141 http://stackoverflow.com/a/1493058/6309 – VonC Jan 20 '15 at 09:36
4

Drop to a command line and type:

ssh-keygen -t rsa

And follow the prompts there. I'm pretty sure git's doing exactly that under the hood for you.

Sean
  • 9,888
  • 4
  • 40
  • 43