16
$ ssh usaname@login.somehost.no

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 Answers5

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.

Ronald Blaschke
  • 731
  • 6
  • 5
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.

Oliver Crow
  • 171
  • 1
  • 2
  • 3
  • I've set `HOME` to `%USERPROFIEL%` in environment variables before the cygwin installed. So... /home/ 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 '18 at 03: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%).

  • 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. – Charles Roberto Canato Oct 27 '20 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. – Charlie Reitzel Oct 28 '20 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.

VarunAgw
  • 313
  • 4
  • 12
0

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

Greg Hewgill
  • 6,849
  • 3
  • 30
  • 26