Creating a SSH key with ssh-keygen does not create the .ssh folder
Asked Answered
B

8

49

I am trying to create my public/private rsa key pair with msysgit

I run this command:

ssh-keygen -C "[email protected]" -t rsa

Everything looks fine, I have the message

Enter file in which to save the key (/c/Users/user/.ssh/id_rsa)

Then I have the confirmation:

Your public key has been saved in project.pub

But I can't access the folder! It does not exist, it is not even an hidden folder. I don't understand why it does not generate. I am using Windows 7 Ultimate.

Barmaid answered 19/6, 2010 at 15:35 Comment(2)
more than that. If you create folder - keys not appears after successful generating. Has you resolved you problem? Stuck the same nowMagdalenamagdalene
If you enter project as your file, this file gets created in your current directory. If you want it inside the .ssh folder, either cd inside or enter the full path.Matteroffact
P
39

You can start with creating the expected folder, and check you can access it:

mkdir "%USERPROFILE%\.ssh"
dir "%USERPROFILE%\.ssh"
cd "%USERPROFILE%\.ssh"

Make sure you do not have a Windows environment variable named HOME, which would take precedence when using ssh.exe or ssh-keygen.exe commands from a CMD session (as opposed to a bash session).

echo HOME='%HOME%'

You can use (from CMD or bash)

ssh-keygen -C "vonc@xxxx" -t rsa -P "" -f ~/.ssh/mykey
                                       ^^^^^^^^^^^^^^^

That will create a %USERPROFILE%\.ssh\mykey and %USERPROFILE%\.ssh\mykey.pub.


As a test, I just created my key without any problem (Seven Ultimate 64bits, msysgit 1.6.5.1.1367.gcd48)

$ ssh-keygen -C "vonc@xxxx" -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/VonC/.ssh/id_rsa):# just press enter
                                                                # to accept the
                                                                # default location
Enter passphrase (empty for no passphrase):                     
Enter same passphrase again:
Your identification has been saved in /c/Users/VonC/.ssh/id_rsa.
Your public key has been saved in /c/Users/VonC/.ssh/id_rsa.pub.
The key fingerprint is:
xx:yy:zz:aa:bb:cc:... vonc@xxxx

With the result:

VonC@P ~/.ssh
$ ls -alrt
total 10
-rw-r--r--    1 VonC Administ      642 May 23 21:47 known_hosts
drwxr-xr-x   43 VonC Administ    16384 Jun 15 17:01 ..
-rw-r--r--    1 VonC Administ      398 Jun 19 16:14 id_rsa.pub
-rw-r--r--    1 VonC Administ     1675 Jun 19 16:14 id_rsa
drwxr-xr-x    2 VonC Administ        0 Jun 19 16:14 .

Could you check in your bash session (so not CMD) what value your $HOME environment variable is set?

VonC@P ~/.ssh
$ env|grep HOME
HOMEPATH=\Users\VonC
HOME=/c/Users/VonC     # <=== this must be correctly set
HOMEDRIVE=C:
Punchball answered 19/6, 2010 at 16:16 Comment(3)
Thanks VonC, you made me realized that my error was that I was typing a name when I was asked to enter file in which to save the key. I just hitted Enter and it generated id_rsa and id_rsa.pub files. Now it works perfectlyBarmaid
@couellet: thank you for this feedback. I have edited my answer to reflect it.Punchball
Check if the .ssh is not a symlink (Mackup and others do this for backups).Scheelite
K
43

I had the same problem and I realized I was trying to enter a file name when it asks for the following "Enter file in which to save the key (c/users/user.name/.ssh/id_rsa)"

Rather just enter nothing and press Enter key to use the default and you will move on.

Kirtley answered 15/1, 2016 at 15:56 Comment(3)
I realized it requires full path, not just a name, otherwise file will be created at the cmd current working directory. Moreover if you type name only, you will see in summary default path "bla bla saved in /c/Users/{UserName}/.ssh/id_rsa_name"Reconciliatory
@Reconciliatory - FWIW, when I made the mistake of typing name only, it did not give the full path; it just said ".. saved in myfilename." [If I hit enter to accept the default path, then it has the full path to that default location.]Plump
didn't work for me until I generated it with no file name specifiedFranck
P
39

You can start with creating the expected folder, and check you can access it:

mkdir "%USERPROFILE%\.ssh"
dir "%USERPROFILE%\.ssh"
cd "%USERPROFILE%\.ssh"

Make sure you do not have a Windows environment variable named HOME, which would take precedence when using ssh.exe or ssh-keygen.exe commands from a CMD session (as opposed to a bash session).

echo HOME='%HOME%'

You can use (from CMD or bash)

ssh-keygen -C "vonc@xxxx" -t rsa -P "" -f ~/.ssh/mykey
                                       ^^^^^^^^^^^^^^^

That will create a %USERPROFILE%\.ssh\mykey and %USERPROFILE%\.ssh\mykey.pub.


As a test, I just created my key without any problem (Seven Ultimate 64bits, msysgit 1.6.5.1.1367.gcd48)

$ ssh-keygen -C "vonc@xxxx" -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/VonC/.ssh/id_rsa):# just press enter
                                                                # to accept the
                                                                # default location
Enter passphrase (empty for no passphrase):                     
Enter same passphrase again:
Your identification has been saved in /c/Users/VonC/.ssh/id_rsa.
Your public key has been saved in /c/Users/VonC/.ssh/id_rsa.pub.
The key fingerprint is:
xx:yy:zz:aa:bb:cc:... vonc@xxxx

With the result:

VonC@P ~/.ssh
$ ls -alrt
total 10
-rw-r--r--    1 VonC Administ      642 May 23 21:47 known_hosts
drwxr-xr-x   43 VonC Administ    16384 Jun 15 17:01 ..
-rw-r--r--    1 VonC Administ      398 Jun 19 16:14 id_rsa.pub
-rw-r--r--    1 VonC Administ     1675 Jun 19 16:14 id_rsa
drwxr-xr-x    2 VonC Administ        0 Jun 19 16:14 .

Could you check in your bash session (so not CMD) what value your $HOME environment variable is set?

VonC@P ~/.ssh
$ env|grep HOME
HOMEPATH=\Users\VonC
HOME=/c/Users/VonC     # <=== this must be correctly set
HOMEDRIVE=C:
Punchball answered 19/6, 2010 at 16:16 Comment(3)
Thanks VonC, you made me realized that my error was that I was typing a name when I was asked to enter file in which to save the key. I just hitted Enter and it generated id_rsa and id_rsa.pub files. Now it works perfectlyBarmaid
@couellet: thank you for this feedback. I have edited my answer to reflect it.Punchball
Check if the .ssh is not a symlink (Mackup and others do this for backups).Scheelite
R
9

I faced a similar issue while creating a SSH key and I resolved it this way.

When you use ssh-keygen -t rsa to generate a SSH key and it prompts you to

Enter file in which to save the key (/Users/iamarasekera/.ssh/id_rsa):

Do not give any file name. Instead, just press "Enter" key and go ahead.

Then it will create .ssh folder and inside that folder it will generate the 2 files id_rsa and id_rsa.pub.

You will also see the message Created directory '/<path to your current folder>/.ssh'. on your command prompt.

Next, it will prompt you toEnter passphraseand you better not skip it.

Check this out for your reference.

enter image description here

Note: If you enter a file name when it prompts you to enter a file name to save the key it creates 2 file as <filename> and <filename>.pub inside the directory where you are currently located without creating a .ssh folder.

Hope this helps.

Roots answered 27/6, 2019 at 14:59 Comment(2)
i was wondering why it was not creating anything lol. this explains , thnksShelia
inside the directory where you are currently located without creating a .ssh folder. is the magic phrase hereHawkeyed
S
9

If you already have a key called "id_rsa" and you want to save a new one in a different name, you need to provide the whole path, if I understood it. So when it asks:

Enter file in which to save the key (/c/Users/myname/.ssh/id_rsa):

You can type /c/Users/myname/.ssh/new_key and it will be created (I just tested).

Strikebreaker answered 22/8, 2019 at 15:1 Comment(0)
A
6

I faced similar situation, Solution that worked for me has been described below.

When following message comes while creating the key -

Enter file in which to save the key (C:\Users\aditya/.ssh/id_rsa):

Just Press Enter Here , do not provide any filename else the key will get created in your Present Working Directory.

Acuff answered 28/9, 2022 at 13:43 Comment(0)
P
1

The filename alone is not enough!

you need to specify full path. For your requirement

/c/Users/user/.ssh/project

Otherwise, your keys will be stored in the current directory of the command prompt.

For example, if you were running from /c/project your keys will be stored /c/project/project and /c/project/project.pub

Prison answered 24/7, 2022 at 7:16 Comment(0)
E
0

This worked for me.. Refer link below

http://ekawas.blogspot.co.uk/2007/03/solving-pesky-ssh-issues-in-cygwin.html

edit the passwd file in c:/cygwin64/etc. Open it with wordpad

edit home/YOUR_NAME to /cygdrive/c/Documents and Settings/YOUR_NAME

Enharmonic answered 24/2, 2014 at 11:4 Comment(0)
S
0

This is late but I after the solutions provided here didn't make a change, I simply ran Git Bash as administrator. It worked as expected this way.

Serried answered 28/11, 2021 at 14:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.