前言

最近用 scp 命令在服务器之间对拷文件,出现错误提示,大体是 ”ssh remote host identification has changed “。报错退出并无法完成复制任务,大体意思就是原来存过RSA KEY,但现在对拷的远程机发生了变化才导致的不匹配。

具体提示如下:

root@localhost:~# scp -P 22 root@ip:/root/zctou_file.tar.gz  /root/zctou
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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
SHA256:ADCe7AIUskJjs3rususf0L7ATUj00sr5cZLGoerkcxc.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending RSA key in /root/.ssh/known_hosts:1
  remove with:
  ssh-keygen -f "/root/.ssh/known_hosts" -R "XXX.XX.XX.XX" //远程机ip
RSA host key for XXX.XX.XX.XX has changed and you have requested strict checking.
Host key verification failed.

解决办法

错误提示: Offending RSA key in /root/.ssh/known_hosts:1

上面错误提示已经很清楚了,只要删除/root/.ssh/known_hosts文件的第一行,并重新认证即可。

办法一:

1. vi /root/.ssh/known_hosts

2. 除掉第一行,保存并退出:wq

办法二:

ssh-keygen -R "上面提示的远程机IP"

输入命令后会提示更新成功

root@localhost:~# ssh-keygen -R "XXX.XX.XX.XX"
# Host XXX.XX.XX.XX found: line 1
/root/.ssh/known_hosts updated.

办法三:

sed -i '1d' /root/.ssh/known_hosts

这命令会删除 /root/.ssh/known_hosts 的 第1行。

文章目录