17

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.

Stefano Mtangoo
  • 6,017
  • 6
  • 47
  • 93

3 Answers3

16

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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
3

Look in ~\Users\~\AppData\Roaming\_ssh\known_hosts.

See also: http://comments.gmane.org/gmane.comp.web.curl.general/12593

i486
  • 6,491
  • 4
  • 24
  • 41
  • I cannot find it in my Computer (Windows 10) – Stefano Mtangoo Oct 05 '15 at 10:00
  • Enable "show hidden files". Probably there is hidden folder before AppData. `Local Settings` or similar. If there is no `known_hosts` file or `_ssh` folder under `AppData\Roaming`, you can create it. – i486 Oct 05 '15 at 10:05
  • 1
    So this is standard Path? – Stefano Mtangoo Oct 05 '15 at 10:36
  • `AppData\Roaming` folder structure exists on all Windows systems. In above answer `~` means `...` i.e. the system drive can be `C:`, `D:`, etc. but `Users` folder always exists. Then second `~` is because the username can be any - you replace it with your case. There is system variable `%APPDATA%` which will show specific path - open Prompt window and type `SET` to see it. – i486 Oct 05 '15 at 11:24
  • I mean this full path is the standard for ssh known hosts in Windows – Stefano Mtangoo Oct 05 '15 at 11:27
  • 2
    No. It seems this is application specific file - for SSH library (libcurl). You can check PuTTY for its path - I suppose it is different. – i486 Oct 05 '15 at 11:34
  • On my Windows 10, it was located in `C:\Users\Username\.ssh\known_hosts`. Maybe I installed it differently. – Yoosu Mar 25 '23 at 06:41
2

Not sure about libcurl though. But, for PuTTY users this might be helpful if the PuTTY throws warnings such as WARNING: Server public key has changed So in window known_hosts for PuTTY is SshHostKeys.

that is stored at the HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys location. To reach that location Registry Editor supposed to be used.

  • go to start look for regedit
  • then you will see all the directories on the left pane under computer
  • just like this image says go to HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys location - location
  • then you can modify like you wish Known host options - delete the registry value if you see a warning says WARNING: Server public key has changed
  • If needed you can check the content in the SshHostKeys file using this command REG QUERY HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\SshHostKeys

And then the cache will be cleared. Will be everything new again for that particular entry

aneesh
  • 21
  • 3
  • Thanks for noticing it @MartinPrikryl. I've updated accordingly. Since I was working on one of these issues this seems like the closet question in StackOverflow and thought it might help someone who is looking for help in this regard – aneesh Oct 17 '19 at 15:03