15
$ ssh [email protected]

Could not create directory'/cygdrive/c/Documents and Settings/vidar kongsli/.ssh'.
The authenticity of host 'login.somehost.no (...)' can't be established.
RSA key fingerprint is ....
Are you sure you want to continue connecting (yes/no)? no
Host key verification failed.

$ set | grep HOME

HOME=/cygdrive/d/home/vidar
HOMEDRIVE=C:
HOMEPATH=/cygdrive/d/home/vidar

$ ls ~/.ssh

id_rsa  id_rsa.pub

Any idea why ssh does not use the $HOME environment variable when it tries to locate ~/.ssh?

(edit: fixed formatting)

5 Answers 5

9

Have a look at /etc/passwd. Make sure the entry there matches your expected home directory. It's the second to last field for your user's entry.

6

If your $HOME variable is set, but ssh isn't recognizing it, put this line in /etc/nsswitch.conf:

db_home: /%H

That will set the Cygwin home directory without requiring an /etc/passwd file to exist.

1
  • I've set HOME to %USERPROFIEL% in environment variables before the cygwin installed. So... /home/<myusername> haven't be created (/etc/passwd cannot be found). And cannot using ssh key in %USERPROFILE%. db_home: /%H fix the issue perfectly. Thanks a lot!
    – Marslo
    Sep 30, 2018 at 3:03
3

In /etc/nsswitch.conf:

db_home:  windows

See The db_home setting. This tells Cygwin to just use the Windows %USERPROFILE% directory as the Cygwin $HOME.

This is necessary if, for example, you want to share the same SSH keys between git (GitHub Enterprise) and SSH to various local Unix/Linux systems.

Setting %HOME% at the OS level did not work (even though $HOME in bash correctly reflects the setting).

You can see from the original question that SSH is trying to update the Windows home directory, which in Vidar's older version of Windows is C:\Documents and Settings\vidar kongsli. In current versions (7+, I think), the equivalent is C:\Users\%USERNAME% (or, if Windows is not installed on C:, %SystemDrive%\Users\%USERNAME%).

2
  • This was the 1st one I've tried, but it also did not work for me - SSH kept on trying /home/blablabla, which obviously was not mapped. So far, just the /%H has worked. And, considering the docs, your answer really should be totally functional. Oct 27, 2020 at 20:24
  • Glad you got it working. Since answering, I have updated to Windows 10 and have updated Cygwin. So, currently, I can share SSH keys fine w/out anything in /etc/nsswitch.conf at all (the default, I think). It's not always clear to me why one thing works vs another. But my guess it that it's related to the versions of Windows, Cygwin and SSH. Oct 28, 2020 at 23:51
1

Set db_home in /etc/nsswitch.conf to the path to your home. This is the method recommended by MSYS2.

Adding a HOME environment variable also works.

Git-for-Windows includes env in db_home, which should read your HOME bash variable, however, it is unreliable.

5
  • 1
    Editing how? What did you set db_home to? Jul 23, 2015 at 10:53
  • @AndrewSchulman To the directory I want as my home directory?
    – user291620
    Jul 23, 2015 at 10:58
  • 1
    wow! This is lot of helpful information. Thanks for edit @go2null :)
    – user291620
    Aug 10, 2016 at 20:21
  • This answer does not actually list what the "recommended" linked bug recommends. The linked bug says: db_home: windows cygwin desc
    – Gordon
    Oct 19, 2018 at 15:41
  • I tried the other answers, but this is the one that worked.
    – stark
    Jun 16, 2021 at 17:21
0

Is the variable HOME exported? Try: export HOME then ssh again.

You must log in to answer this question.