SSH WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! への対処法


このようなエラーメッセージが出力された場合の対処法についてです。

```
[root@ltm-i2600-1:Active:Standalone] .ssh # ssh sslo@172.22.2.102
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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:/z+KfLg3oLvSb/mQT9ntx+DqYjNC5277cHPrQdS5mFk.
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:7
RSA host key for 172.22.2.102 has changed and you have requested strict checking.
Host key verification failed.
```

##known_hostsファイルからホスト鍵を削除する

保存されているknown_hostsファイルを見てみる。

```
[root@ltm-i2600-1:Active:Standalone] .ssh # ls
authorized_keys  identity  identity.pub  id_rsa  id_rsa.pub  known_hosts  README
[root@ltm-i2600-1:Active:Standalone] .ssh # cat known_hosts
172.22.2.22 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCS+TkfS/QmqVcLx3gZAH/VNH4Q76bRRobZcaRk/BJ0Bcft12nDlCVDTTvoqERWuVrhZYfZW/W65u4UnupFjP7vgjRDAU/5o+vD8Otk6oicFFLrbyID0UoWZjqpC4ykORv4KQtuOBgRTHr59Kx7Fpog8HBppD08y9g7ScCkZAV2kpG5qin+I2WTKdEzZ2NJMgTowlSLjGNbFEa9jMWJwf2/kT3HKhDpInJj/Lavt+JxPZUxLQYAHe0ENyYPDYnIXyuSfde2I1qKRDFKGfN3sbWahK9deatRNx5lFW+QCgrglhn4QRgIRU/CoRtpblgvhXdGkIeaIDmsjkGOkv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oVWblAH2d0WHYNOW1HzGy9r1PUTnNyS4vPeJez6oUJ3QPtWxCJnTK7DHBISkXqAenA9fQysxpvTqd4xmZVh86/OdsDCofAxtoJS0kqj6IHq9ydEBGLR+v9SnW8xS8Ll2pp66PBi7fLVLAYWrh728cHhPO0fRQir6f
192.168.199.103 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQChzxjo0qrgXfhRxLc/RAcQspfcVmfAKUNCSa78xaz3qTER3TJkNrzl6GWVR2UUYUzc/8CnYP5I71ov609lzKmkix3k3G9qzUwXeBhS1k1O5VKsyeYMg1wkCr6XtLv9Nxm+vZcXYtER/nZwZF3oTWvdosb2gGh52lrkkY3DlFhxfCYr3fadcUp9PbtoaBqTqITRTG3qOguTYn6FU8KFIhQ9JNVgvZsIVI3X80QYu3zconT2C4YIeol4nbvqOQgp5bD/F9H38nhpukPAmvgIG6A7Fp5oAmfGh7siz+m+eJQymDp7WxxLdytz+sQKdO5rFwJ+BqO5IAjTTsY9HLuyQEM/
192.168.199.102 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAa8DBybTDXTBKrE1fXrT/5qYUE1VX6sjg53lMWfhHBViTaDCIplkzvi+V1wO2duGC3ZgYidyGlrqQ8wVCGHJootd9pa6u77/T3SKIF8RgsMtFfiCYSN48ImEegH9l7HvxS2AgH6p1dCDvAlM7Gpi/YT6KOHRBNihz1D+bRX0WTmuoQs6JlB3+4qycqbd61JF6jEnLfNEeDFrdwSz7rRV1VW8ZrpB1T+97xF+RL3DuTCml115Qu4MdPijtMV8pC1e27YYUztX3G6Ar0FGWSdOqmu6sP0CwM19H2921s20JOatjeZFB4LkTJ+dxXtntUVrDjjShJuDL3OhxKuFivstV
```

ssh-keygenコマンドの-Rオプションで該当列を削除する。

```
[root@ltm-i2600-1:Active:Standalone] .ssh # ssh-keygen -R 172.22.2.102
# Host 172.22.2.102 found: line 7
/root/.ssh/known_hosts updated.
Original contents retained as /root/.ssh/known_hosts.old
```

接続できるようになった。

```
[root@ltm-i2600-1:Active:Standalone] .ssh # ssh sslo@172.22.2.102
The authenticity of host '172.22.2.102 (172.22.2.102)' can't be established.
RSA key fingerprint is SHA256:/z+KfLg3oLvSb/mQT9ntx+DqYjNC5277cHPrQdS5mFk.
RSA key fingerprint is MD5:33:64:5e:c6:bd:11:f2:b2:fe:42:04:46:81:35:30:9d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.22.2.102' (RSA) to the list of known hosts.
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.15.0-118-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Thu Oct 15 06:50:58 UTC 2020

  System load:  0.0                Users logged in:       1
  Usage of /:   13.2% of 15.68GB   IP address for ens160: 192.168.199.102
  Memory usage: 4%                 IP address for ens192: 172.22.2.102
  Swap usage:   0%                 IP address for ens256: 10.1.92.102
  Processes:    192                IP address for ens224: 10.1.82.102


 * Canonical Livepatch is available for installation.
   - Reduce system reboots and improve kernel security. Activate at:
     https://ubuntu.com/livepatch

105 packages can be updated.
50 updates are security updates.

Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings


*** System restart required ***
Last login: Thu Oct 15 06:37:00 2020 from 172.22.100.124
```

こちらの記事を参考にしました。
[「SSHホスト鍵が変わってるよ！」と怒られたときの対処](https://qiita.com/hnw/items/0eeee62ce403b8d6a23c)