eparvan
eparvan

Reputation: 1729

How to get rid of "REMOTE HOST IDENTIFICATION HAS CHANGED" message

I have several virtual machines installed on my computer, to which I connect via ssh:

ssh vm1@localhost

or

ssh vm2@localhost

So every time I connect to different vm I need to edit my ~/.ssh/known_hosts file in order to get rid of: “WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!” message.

Is there any way to trust automatically all VMs on localhost?

Upvotes: 13

Views: 36455

Answers (5)

Dmytro
Dmytro

Reputation: 2309

For bitbucket users faced this issue after May 2023.

Do the following in the git terminal:

ssh-keygen -R bitbucket.org && curl https://bitbucket.org/site/ssh >> ~/.ssh/known_hosts

More details in the guide.

Upvotes: 0

goodhyun
goodhyun

Reputation: 5002

ssh-keygen -R YourIPorDomainName

With this, ~/.ssh/known_hosts will be updated along with .old backup.

Upvotes: 3

megelon
megelon

Reputation: 139

You can try modifying the ~/.ssh/known_hosts file.

Deleating all inside the file is an option**, you can do it with nano or your favorite editor. Eg.:

nano ~/.ssh/known_hosts

Try again the connection, it should work

ssh -i ~/.ssh/yourkey.pub vm1@localhost

**nevertheless it would be a good practice if you only delete the row associated to the conflict.

Upvotes: 13

jwillikers
jwillikers

Reputation: 234

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.

Upvotes: 3

Quentin
Quentin

Reputation: 943223

In your configuration (e.g. ~/.ssh/config) you can trash the known hosts for a specific hostname:

Host localhost
        HostName localhost
        UserKnownHostsFile=/dev/null
        StrictHostKeyChecking=no

credit

Upvotes: 25

Related Questions