【GitHub】「WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!」とエラーが出た時の対処

【GitHub】「WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!」とエラーが出た時の対処

久しぶりにgit pushしようとしたらなんか怒られました。

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:**************************************.
Please contact your system administrator.
Add correct host key in /Users/[username]/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/satokichi/.ssh/known_hosts:1
Host key for github.com has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

OS再インストールとか、何かの拍子にIPアドレスが変わったりするとホスト鍵が変わるらしく、更新しないといけないみたいです。

で、下の通り打ったら解決しました。

$ ssh-keygen -R github.com

# Host github.com found: line 1
/Users/[username]/.ssh/known_hosts updated.
Original contents retained as /Users/[username]/.ssh/known_hosts.old

pullとかpushしようとすると

The authenticity of host 'github.com (20.27.177.113)' can't be established.
ED25519 key fingerprint is SHA256:+**************************************.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?

と聞かれるのでyes+[Enter]とタイプしましょう。

これで直りました。