[git] Saving ssh key fails

i just started a Git tutorial and I get to a deadend: I try to generate a rsa key part and it fails. I did this, in git bash:

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

And i got this:

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Eva/.ssh/id_rsa):
enter passphrase:
enter same passphrase again:
open /c/Users/Eva/.ssh/id_rsa failed: no such file or directory.
Saving the key failed:/c/Users/Eva/.ssh/id_rsa.

I tried to save in a different folder and it went OK. but now i do the command ssh -T [email protected] and it gives me the error permisson denied (publickey).

This question is related to git github ssh-keys

The answer is


Your method should work fine on a Mac, but on Windows, two additional steps are necessary.

  1. Create a new folder in the desired location and name it ".ssh." (note the closing dot - this will vanish, but is required to create a folder beginning with ".")
  2. When prompted, use the file path format C:/Users/NAME/.ssh/id_rsa (note no closing dot on .ssh).

Saving the id_rsa key in this location should solve the permission error.


I had the same issue. I had to provide the full path using Windows conventions. At this step:

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

Provide the following value:

c:\users\eva\.ssh\id_rsa


If you're using Windows, the unix-style default path of ssh-keygen is at fault.

In Line 2 it says Enter file in which to save the key (/c/Users/Eva/.ssh/id_rsa):. That full filename in the parantheses is the default, obviously Windows cannot access a file like that. If you type the Windows equivalent (c:\Users\Eva\.ssh\id_rsa), it should work.

Before running this, you also need to create the folder. You can do this by running mkdir c:\Users\Eva\.ssh, or by created the folder ".ssh." from File Explorer (note the second dot at the end, which will get removed automatically, and is required to create a folder that has a dot at the beginning).

c:\Users\Administrator\.ssh>ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/Administrator/.ssh/id_rsa): C:\Users\Administrator\.ssh\id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\Administrator\.ssh\id_rsa.
Your public key has been saved in C:\Users\Administrator\.ssh\id_rsa.pub.
The key fingerprint is:
... [email protected]
The key's randomart image is:...`

I know this is an old thread, but I thought the answer might help others.


For windows use enter button 3 times

Enter file in which to save the key (/c/Users/Rupesh/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again:

its work for me...


I struggled with the same problem for a while just now (using Mac). Here is what I did and it finally worked:
(1) Confirm the .ssh directory exists:

#show all files including hidden
ls -a 

(2) Accept all default values by just pressing enter at the prompt

Enter file in which to save the key (/Users/username/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 

You should get a message :

Your identification has been saved in /Users/username/.ssh/id_rsa.
Your public key has been saved in /Users/username/.ssh/id_rsa.pub.
The key fingerprint is:
BZA156:HVhsjsdhfdkjfdfhdX+BundfOytLezXvbx831/s [email protected]
The key's randomart image is:XXXXX

PS If you are configuring git for rails, do the following (source):

git config --global color.ui true
git config --global user.name "yourusername"
git config --global user.email "[email protected]"
ssh-keygen -t rsa -C "[email protected]" 

(then accept all defaults by pressing enter)


On Windows 8.1 using CMDER, I created the ssh key with this file path /c/Users/youruser/.ssh/id_rsa_whatever, the problem was the : that I was using. With this path I didn't create the folder before running the command, there is no need to run mkdir because the command will create the folder automatically.


You have to create the .ssh folder yourself for saving ssh keys.

By the way, I used this path style: C:/Users/you/.ssh/id_rsa


For Linux on terminal use:

ssh-keygen -t ed25519 -C "<comment>"

this generate new modeled key. Or can create as:

ssh-keygen -t rsa -b 2048 -C "any comment"

Then continue following terminal.. give any name to the file as asked Again follow it with empty passphrase..and continue

Then goto the /home/user/.ssh/id_ed25519 or /home/user/.ssh/id_rsa (is hidden file..look by doing ctrl+h to unhide hidden file) and copy it to gitlab => profile => setting => ssh => create new key there by pasting copied key and NOTE: public key always starts with ssh. Enjoy! Help:gitlab-Help


I was using bash on windows that came with git. The problem was I assumed the tilde (~) which I was using to denote my home path would expand properly. It does work when using cd, but to fix this error I had to just give it the absolute path.


For MacOS

Open terminal and make sure you have .ssh directory.

On your home(~) folder enter ls -hal and you will see all hidden directories and make sure you have .ssh directory, if not do mkdir .ssh

then enter this ssh-keygen -t rsa -C "[email protected]"

then you have: Generating public/private rsa key pair. Enter file in which to save the key (/Users/YOURUSERNAME/.ssh/id_rsa):

press Enter (you don't need to enter nothing if you agree with that path or you need to enter your path from root of volume)

then follow answer what is gonna ask press Enter.

Check it here https://help.github.com/en/enterprise/2.16/user/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent


It looks like you are executing that command from a DOS session (see this thread), and that means you need to create the .ssh directory before said command.

Or you can execute it from the bash session (part of the msysgit distribution), and it should work.


In Windows I had to create the environment variable HOME pointing to my user profile first (C:\Users\<name>) or whatever directory you prefer.

Then start a new command line window, create a a .ssh directory in your user profile or choosen diretory using mkdir ".ssh" command.

After doing that I was able to use the ssh-keygen without any path problems.


I faced the same problem. Solution on windows:

  1. open start menu and type cmd
  2. Right and choose run as administrator
  3. Then type cd Users_YOURUSERNAME_\ Replace "YOURUSERNAME" with your windows account name
  4. The type: mkdir .ssh

This will create a .ssh folder.


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to github

Does the target directory for a git clone have to match the repo name? Issue in installing php7.2-mcrypt How can I switch to another branch in git? How to draw checkbox or tick mark in GitHub Markdown table? How to add a new project to Github using VS Code git clone error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 How to add empty spaces into MD markdown readme on GitHub? key_load_public: invalid format git - remote add origin vs remote set-url origin Cloning specific branch

Examples related to ssh-keys

How to solve "sign_and_send_pubkey: signing failed: agent refused operation"? Windows 10 SSH keys How can I remove an SSH key? ssh-copy-id no identities found error SSH Key - Still asking for password and passphrase Using SSH keys inside docker container Failed to add the host to the list of know hosts Cloning git repo causes error - Host key verification failed. fatal: The remote end hung up unexpectedly Push to GitHub without a password using ssh-key how to generate public key from windows command prompt