I'm working with libcurl as SFTP and its great. I want to check for the host am about to connect if it exists in the hosts file. In Linux I can easily find known hosts file as it is almost always in ~/.ssh/known_hosts
. I wanted to know if Windows maintains the same thing or there is no standard as to where such file resides in Windows.
The ~/.ssh/known_hosts
is a *nix path used by OpenSSH. The ~
is resolved to the account's home directory, which is specified in /etc/passwd
file. The home defaults to /home/username
folder on Linux.
The OpenSSH is Linux software. It does not run on Windows on its own.
Though it can run on *nix emulation on Windows and there are also Windows clones of OpenSSH. So in the end, your question is about what emulation or clone do you run on the Windows machine and how that maps/re-implements the access to ~/.ssh/known_hosts
.
Win32-OpenSSH (Windows clone of OpenSSH by Microsoft): It goes to your Windows account profile folder. I.e. typically to C:\Users\username\.ssh
.
See also my guide for Setting up SSH public key authentication on Win32-OpenSSH.
Cygwin emulator: On my installations, all *nix-like paths are actually stored in C:\cygwin64
(C:\cygwin
on 32-bit).
So the /home/username/.ssh/known_hosts
is in C:\cygwin64\home\username\.ssh\known_hosts
.
Note that Windows SSH clients usually do not use the known_hosts
. They have a different host key cache/storage.
For example widely used Windows SSH client, PuTTY, stores know host keys to Windows registry to HKCU\Software\SimonTatham\PuTTY\SshHostKeys
key. For details, see the answer by @aneesh.