3

I have just installed a fresh MinGW installation on Windows 7 64bit using the Graphical User Interface Installer (the recommended approach) following the instructions given here and keeping the default options (i.e. installation in C:\MinGW) - hopefully without missing any steps or messing things up in any way.

However, when running the ssh command, I get the following error:

C:\Users\myusername>ssh username@host
Could not create directory '/home/myusername/.ssh'.
The authenticity of host 'host (host-ip)' can't be established.
RSA key fingerprint is fingerprint.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/myusername/.ssh/known_hosts).

So, I basically have to confirm the connection every time.
Why does this happen and how do I fix it?

4 Answers 4

2

After some trial and error, I have found the solution(s) to the problem.

Automated solution (for the hasty)

  1. Go to (your-MinGW-installation-directory)\msys\1.0.
    (in my case, which is also the default, that would be C:\MinGW\msys\1.0).
  2. Run msys.bat.

This will start the MinGW Shell, which will create the path
(your-MinGW-installation-directory)\msys\1.0\home\(your-username)
automatically and ssh should now work just fine.


Manual solution (basically create the path required by hand):

  1. Go to (your-MinGW-installation-directory)\msys\1.0.
  2. Create a home directory.
  3. Inside the home directory create a directory with the same name as your username.

So, now the path
(your-MinGW-installation-directory)\msys\1.0\home\(your-username)
is available and ssh should work just fine.


Here is what you should get if everything went well:

C:\Users\myusername>ssh username@host
The authenticity of host 'host (host-ip)' can't be established.
RSA key fingerprint is fingerprint.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'host,host-ip' (RSA) to the list of known hosts.

Note
Since the MinGW Shell could create the path needed (without Windows UAC nagging about a thing), I guess this has nothing to do with persmissions. It is probably an omission of the MinGW installation.

1

How to enable SSH in Windows to update my known_hosts file so that I am not always prompted

Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts 
(/home/myusername/.ssh/known_hosts).

I spent all day trying to figure this out for git-bash for Windows (which I believe uses mingw64 which I believe is a descendant of msys). I'm sure it is a permission error, but I could not find anything that states how to change the Unix permissions (i.e. chmod xxx ...) of a folder or file that is really controlled by Windows. None of the following worked:

  • Creating the ~/.ssh folder in my Windows User's home directory (cd ~ --> C:\User\username)
  • Creating the /home/username/.ssh folder in the git-bash root directory (cd / --> C:\Program Files\Git)
  • Creating the .ssh/known_hosts file in both locations and changing the Windows permissions to Full Access

This worked:

  • Changing the line in the file C:\Program Files\Git\etc\nsswitch.conf:

    From: db_home: env windows cygwin desc
      To: db_home:     windows cygwin desc
    

Why??? I have no idea!!

1
  • 1
    Welcome to Super User. This is an old, self-answered question. You may have had a similar symptom, but there's no indication that the OP had included the env. Might you have encountered the symptom simply because you created an error by including it?
    – fixer1234
    Dec 1, 2018 at 3:23
0

Manually add the rsa key to the .ssh/known_hosts file

Unsure why it's happening, my guess is permission issue if it can't even create the file in the first place

1
  • Thanks. However, I didn't really know where .ssh was supposed to be until I found my answer (which made adding the rsa key manually redundant). May 28, 2014 at 20:48
0

For anyone using msys2 and having the same error:

Change the the line in the file /etc/nsswitch.conf to:

db_home: windows cygwin desc

(From this answer)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.