Skip to main content

ssh: Cleaning known_hosts obsolete entries

One thing that bothers me a lot when using ssh with VMs in my homelab is that I re-use IPs after destroying/recreating VMs. My .ssh/known_hosts then grows and contains a lot of obsolete entries, and eventually, it ends up conflicting.

Here the trick to disable strict host checking on connect for a subset of IPs. Just add the following in .ssh/config:

$ cat ~/.ssh/config
Host 10.2.1.*
  StrictHostKeyChecking no

Another possiblity is to remove them. Simply use ssh-keygen -R:

$ ssh-keygen -R ""
# Host found: line 40
# Host found: line 41
# Host found: line 42
/home/mycroft/.ssh/known_hosts updated.
Original contents retained as /home/mycroft/.ssh/known_hosts.old