It seems that every time I accept a new host key, ssh (I've tested 8.6p1 and 9.3p2) does the following steps:
- Move the
known_hostsfile toknown_hosts.old; - Create a new
known_hostsfile; - Copy the contents of
known_hosts.oldtoknown_hosts; - Add the new entry to the new
known_hosts.
All well and good, except that, like many people, I've put my dotfiles under version control. The known_hosts file is a link to a file in my git repository. After all, if I've accepted a host key on my desktop, then I don't want to risk a MITM if I connect to the same host from my laptop. That's the whole point of the known_hosts file, after all.
The above procedure followed by ssh doesn't play nice: after I accept a new host, it's known_hosts.old which is a link to my version-controlled file, which never gets updated.
How do I tell ssh to please stop creating known_hosts.old and just edit known_hosts directly? I have no need for such a coarse backup method anyway - the file is already under version control. I've perused TFM but I didn't find any such option.
.sshunder version control?~/.sshis a normal directory with standard structure composed of normal files which is itself under version control on its own". In this case, no files in it need to be symlinked to be under version control (exactly opposite is true, better not symlink anything into outside to have it version-controlled), and no problem like described will happen. At least, not with Git.~/.sshto directory under version control. I have this configuration for years and it works perfectly.