You can disable host checking specifically for localhost
by setting NoHostAuthenticationForLocalhost
to yes
in ~/.ssh/config
as follows.
NoHostAuthenticationForLocalhost yes
Note that this does not work when connecting to localhost
on another machine through jump hosts.
Alternatively, you could still achieve host checking like normal by defining a distinct HostKeyAlias
for each host.
This has the added benefit of working over jump hosts, too.
The following example configuration of ~/.ssh/config
demonstrates this.
Host vm1
HostName localhost
HostKeyAlias vm1.localhost
Host vm2
HostName localhost
HostKeyAlias vm2.localhost
This is recommended for this situation by the ssh_config manpage.
HostKeyAlias
Specifies an alias that should be used instead of the real host name when looking up or saving
the host key in the host key database files and when validating host certificates. This
option is useful for tunneling SSH connections or for multiple servers running on a single
host.