WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

为了能让容器(172.17.0.3)能通过ssh免密登录宿主机,需要将宿主机上的公钥复制到容器中,在宿主机中执行命令如下:

		    ssh-copy-id 172.17.0.3

但是执行命令时,提示如下错误:

[root@fanhao-test ~]# ssh-copy-id 172.17.0.3
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: ERROR: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ERROR: @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
ERROR: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ERROR: IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
ERROR: Someone could be eavesdropping on you right now (man-in-the-middle attack)!
ERROR: It is also possible that a host key has just been changed.
ERROR: The fingerprint for the ECDSA key sent by the remote host is
ERROR: SHA256:/oObhd2HdjsRl+O1Z0NZ4/CMgBzlf3+xnitJKb4ohN4.
ERROR: Please contact your system administrator.
ERROR: Add correct host key in /root/.ssh/known_hosts to get rid of this message.
ERROR: Offending ECDSA key in /root/.ssh/known_hosts:2
ERROR: ECDSA host key for 172.17.0.3 has changed and you have requested strict checking.
ERROR: Host key verification failed.

提示远程容器中公钥信息改变了,需要删除掉旧信息,然后重新复制。

解决办法:

删除远程中旧的公钥信息,在宿主机中执行如下命令:

			ssh-keygen -R 172.17.0.3

然后重新把宿主机的公钥复制到远程容器172.17.0.3中,在宿主机中执行如下命令:

		    ssh-copy-id 172.17.0.3

最后提示copy成功:

[root@fanhao-test ~]# ssh-copy-id 172.17.0.3
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '172.17.0.3 (172.17.0.3)' can't be established.
ECDSA key fingerprint is SHA256:/oObhd2HdjsRl+O1Z0NZ4/CMgBzlf3+xnitJKb4ohN4.
ECDSA key fingerprint is MD5:bc:fd:bb:38:5b:d7:41:97:a8:02:aa:89:81:75:c5:c4.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.17.0.3's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '172.17.0.3'"
and check to make sure that only the key(s) you wanted were added.

至此问题解决。


版权声明:本文为u010502101原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。