当通过 ssh-copy-id -i ~/.ssh/id_rsa.pub root@IP,命令配置免密登陆的时候出现如下问题:
/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:6S5JqT1YG+i1Mv9OpkDewUZ+ApQkJQQ7j6bT3ajAxjo.
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:4
ERROR: ECDSA host key for IP地址 has changed and you have requested strict checking.
ERROR: Host key verification failed.
这是因为,需要登陆的主机已经存在于 known_hosts 文件中,但是 key 的信息改变了,所以我们只要删除 known_hosts 文件中该主机的 key 信息,然后重新执行一遍 ssh-copy-id -i ~/.ssh/id_rsa.pub root@IP 就好了。
1)根据 行头部的ip 或则和hostname 信息,删除 known_hosts 中的信息:
2)重新执行 ssh-copy-id -i ~/.ssh/id_rsa.pub root@IP
3)大功告成