3

While trying to clean up my SSH config and key files on my iMac (macOS Monterey 12.1), I tried to SSH using the verbose flag (-v). This generated output including the following lines:

...
debug1: load_hostkeys: fopen /Users/clint/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
...

I know that I tried to create a backup of my known_hosts file (and called it "known_hosts2") but I've since deleted it.

Does anyone know how can I find out why SSH still references (and thinks I have) an old file called 'known_hosts2'?

Thanks!

  • Have you tried `locate known_hosts`? – Paul Jan 29 '22 at 15:42
  • I tried it and it only found a Ruby file in Homebrew (known_hosts.rb). I'll read up on using 'locate' but this has made me realize that my original title for this post "How can I find all known_hosts files?" is misleading. What I really want to do is find out why SSH thinks I still have a file named 'known_hosts2'. I will re-title this post. Thank you. – Clint Laskowski Jan 29 '22 at 15:46

2 Answers2

5

The default configuration for ssh in openssh has UserKnownHostsFile set to ~/.ssh/known_hosts and. ~/.ssh/known_hosts2. The config is similar for GlobalKnownHostsFile except it looks for these files in /etc/ssh as seen in the man page (https://www.man7.org/linux/man-pages/man5/ssh_config.5.html). So openssh ssh checks those 4 files by default which is what you see in ssh -v.

I'm not sure how much the configuration (and implementation) of MacOS SSH differs from openssh default, but at least in this case they seem to behave the same.

user2313067
  • 166
  • 4
  • I marked this as the correct answer. I think it was just a coincidence that I backed up the 'known_hosts' file and called the backup 'known_hosts2'. This is also the name of the SSH2 file that SSH is looking for in the SSH -v output that I saw. – Clint Laskowski Jan 29 '22 at 19:01
0

To fix $HOME/.ssh/known_hosts2: No such file or directory, you can add a file for UserKnownHostsFile to your SSH config, such as:

UserKnownHostsFile ~/.ssh/known_hosts

To fix /etc/ssh/ssh_known_hosts: No such file or directory and /etc/ssh/ssh_known_hosts2: No such file or directory, you can add a file for GlobalKnownHostsFile to your SSH config, such as:

GlobalKnownHostsFile /dev/null
Slim
  • 133
  • 4