26

I feel like I am missing some fundamental concept as to how the .ssh directory works in windows. I have had no issues when working in OSX/Linux like I am having now. My end goal is simply to move my existing ssh key into the default ~/.ssh directory, and update the config if I so choose (you know, normal ssh key related tasks).

However, any time I have tried to move my existing SSH key over to the ~/.ssh directory, or open it, or even create a config file I just get the following error (in either gitbash, puttygen, etc...):

Puttygen (saving the key to disk):

Overwrite existing file C:\Users\me\.ssh?

or in gitbash (attempting to do anything, including just create the config file):

touch: creating `/c/Users/me/.ssh/config': No such file or directory

cd ~/.ssh

sh.exe": cd: /c/Users/me/.ssh: Not a directory

What am I missing/not understanding?

Kind Regards, u353

u353
  • 990
  • 2
  • 9
  • 16
  • "dot" directories are a unixism that doesn't work well in Windows. e.g. it's impossible to directly create a ".dir" in Explorer (you get "You must type a filename"). try creating the relevant directories yourself using a cmd prompt and try again. – Marc B Apr 14 '14 at 15:31
  • Thanks @Marc B - I guess what I'm wondering is are there any key properties about using the dot configuration folder that won't translate over to my using ssh with a plan-ol-windows /ssh/ directory? Just worried this is somehow one day not going to do something I expect - simply because it's not a dot file, and not in linux.. ie. a program looks for the default location ~/.ssh/ and it's not there. – u353 Apr 14 '14 at 15:42
  • well, the errors would suggest that .ssh is a file, not a directory. puttygen's trying to overwrite it as a file, and gitbash is trying to treat it as a dir. – Marc B Apr 14 '14 at 15:44
  • So how do I get the same functionality of the ~/.ssh folder in windows so I can update/add/modify ssh settings and use it to automatically connect to remote hosts that have my public key? – u353 Apr 14 '14 at 15:53
  • So even at the time of this post, I had puttygen, pageant, and plink installed and running with a passphrase setup and working just fine. What I didn't know was that I needed to add a value for GIT_SSH in my env var's to point to plink.exe... To make matters worse, GitBash HATES good passwords (apparently), and won't accept it when trying to authenticate. I've checked & rechecked my passphrase. Still a no go. Sent an email to Github hoping for the best. – u353 Apr 14 '14 at 18:38

8 Answers8

30

This answer for Windows environment:

At the beginning, Windows didn't have .ssh folder. Create an ssh key file pair like this (ssh-keygen is nowadays a native Windows command, that comes with Windows 10+11):

ssh-keygen -t rsa -b 4096 -C "your_email@example.com" (must run your terminal as administrator).

Your is_rsa and id_rsa.pub files will be placed under C:\Users\your_username\

So, you need to create the folder C:\Users\your_username\.ssh then copy your ssh files (the extensionless private key and the public key ending in .pub) to there.

You also have to create file C:\Users\your_username\.ssh\config and edit it for the first time.

Next ssh will be placed in the .ssh folder automatically.

Note: ~/ under Linux is the equivalent of C:\Users\your_username\ on Windows

Frank N
  • 9,625
  • 4
  • 80
  • 110
dqthe
  • 683
  • 5
  • 8
8

I have created and regularly use a ".ssh" directory on Windows 7; as mentioned in the above comments, Windows Explorer doesn't support them, or more specifically, the error-checking in Windows Explorer does not allow you to give a file name that starts with a period. That same restriction does not exist in the command prompt or powershell.

Also, as mentioned above, it appears you have a file called ".ssh" in your home directory, which must be removed before you can create a folder named ".ssh".

Once such a folder exists, you can open it and change/create files in it using Windows Explorer; it just won't let you name a folder/file ".ssh" directly.

Gitbash should directly allow you to run "rm .ssh" and "mkdir .ssh", at which point everything else should work.

Bryson
  • 81
  • 1
  • 3
5

It is quite possible to add a . in the beginning of a directories name using File Explorer, it can be easily done by adding a . at the end of the directory name as well. For example:

To create a directory named .shh, just add the name as .ssh. and it will be created without any error.

And as @Bryson mentioned, this can be done from the cli as well, without appending a . at the end.

mega6382
  • 9,211
  • 17
  • 48
  • 69
5

Coming to this in 2018, given that on Windows 10 you have the Optional Feature OpenSSH client installed it appears that on Windows a .ssh folder is created for you under C:\Users\<your_username>\.ssh

This is a feature that allows you to use PowerShell to SSH into remote hosts, and seems to be pretty similar in usage to the Linux/Unix equivalent. It was already installed for me when I setup my computer, but you can read the following for how to verify it's installed or install it:

You can check if it's installed by going to Settings -> Manage Optional Features, and then checking if you see OpenSSH in the list. If it is then your .ssh folder is probably in your home directory C:\Users\<your_username>\.ssh. If you need to install it then click "Add a feature", locate OpenSSH Client, click it and click install to install it.

cody.codes
  • 1,384
  • 1
  • 18
  • 24
1

Use git bash on windows go to home directory as

$ cd

then to check .ssh folder on home directory use

$ ls -A 

you will be able to see a ./ssh folder there

$ cd ./ssh
$ ls

you will be able to see the config files if exists

To transfer any key-pair or any files to this folder use below command First to that directory in which you already have key-pair

$ cp name_of_key-pair_file.pem ~/.ssh/
1

First of all, if you want to generate SSH files, all you need to do is run this command:

ssh-keygen

Once you did, .ssh folder will be generated in this path:

C:\Users\your_username\

For checking what files are in .ssh folder you can easily run this command:

ls ~/.ssh

with this above command, you can see all your ssh files which would be like this:

id_rsa   id-rsa.pub

Please note that:

id_rsa : It's a private file and id-rsa.pub : It's a public file

so, if you like to see inside of that file or whatever you like just type this command :

cat ~/.ssh/id_rsa.pub
Babak
  • 93
  • 2
  • 3
0

To solve this problem I used git batsh console

Joselin Ceron
  • 474
  • 5
  • 3
-27

This isn't supported as Windows doesn't recognize dot files as directories.

u353
  • 990
  • 2
  • 9
  • 16