3

I've been trying to sort out the Could not create directory issue with openSSH installed via cygwin, and have tried every solution I can find on the internet, but none of them are working...

I've installed cygwin, it appears to work. I installed openSSH, which also appears to work (i can ssh into other machines).

I've put the cygwin bin folder in the path, so i can run ssh fro mthe command line, and that works too. But every time I run it it gives me the error:

Could not create directory '/home/will/.ssh'
The authenticity of host 'blah (111.222.333.444)' can't be established.
ECDSA key fingerprint is SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
Are you sure you want to continue connecting (yes/no)?

Why is it trying to use that directory? I have set the env. variable HOME to %USERPROFILE%, it prints the correct location when I echo it, and I also have created the .ssh dir and done the ssh-keygen thing there.

I read somewhere that i need to replace home/will in cygwin/etc/passwd, but I don't have that file. And if I use mkpasswd -l to generate it it does not include me as a user, so there's nothing I can replace. I'm really stumped.

What do I need to do/set to make this work?

will
  • 141

3 Answers3

3

If you look inside "/usr/bin/ssh-user-config", you will notice the advise:

    csih_error_multi \
      "There is no home directory set for you in the account database." \
      'Setting $HOME is not sufficient!'

Without touching the Windows user database, the fastest way to define a different home is:

 mkpasswd -d -u "Your_Windows_User_Name" > /etc/passwd
or
 mkpasswd -l -u "Your_Windows_User_Name" > /etc/passwd  

likely "will". As you user is local or is a domain one.

And modify the last but one field "/home/will" with the value you want.

Additional reading, on Windows and Cygwin users:

https://cygwin.com/cygwin-ug-net/ntsec.html
https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-mapping-nsswitch
matzeri
  • 2,531
1

You can edit /etc/ssh/ssh_config and add the following properties:

IdentityFile /C/Users/username/.ssh/id_rsa
UserKnownHostsFile /C/Users/username/.ssh/known_hosts

This still prints the error Could not create directory '/home/username/.ssh'. But apart from that everything works. By the way I am using msys2 but theoretically this should work for you as well.

0

Thanks to matzeri for the hint to look in /usr/bin/ssh-user-conifg. Looking in there, I realized that the script is getting the home directory via a call to getent passwd. When I run that on my system, I see that the home directory its looking for is in /home (which in the Windows file system translates to C:\Cygwin64\home\myusername)

My actual Windows home directory (%USERDIR%) is C:\Users\myusername, which Cygwin sees as /cygdrive/c/Users/myusername.

I discovered that, as an alternative to creating an /etc/passwd file, I can symlink my Windows home directory to the location Cygwin wants:

cd /home
rm -rf myusername
ln -s /cygdrive/c/Users/myusername .

After doing this, SSH has no problem reading the .ssh directory in my Windows home directory.

David C.
  • 1,077