13

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!

2 Answers2

8

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.

2

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