MacOS – SSH to a local VirtualBox with Ubuntu

macossshUbuntuvirtualbox

I installed an Ubuntu server image on VirtualBox.
Next I configured port forwarding 2222=>22.

When I use the following command things work ok :

ssh -p 2222 java@127.0.0.1

Password is prompted and I can login into Ubuntu on VBox.

However when I use :

ssh -p 2222 java@localhost

i get the following

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
………
Please contact your system administrator.
Add correct host key in /Users/cristian/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/cristian/.ssh/known_hosts:2
RSA host key for [localhost]:2222 has changed and you have requested strict checking.
Host key verification failed.

Of course

ping localhost
PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.038 ms

Any idea why ?

Thanks

Best Answer

my workaround for local hosts that get re-installed a lot is to configure ssh so that local IPs use /dev/null for the hosts file (dangerous, be careful).

Related Question