2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

新しいホストをknown_hostsに追加する

Last updated at Posted at 2021-05-17

はじめに

忘れないようにメモ。
ホスト側Ubuntuをアップデートした際にリモートでMacからsshでアクセスする際、以下のような警告がでた。

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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 ECDSA key sent by the remote host is
SHA256:-----------------------------------.
Please contact your system administrator.
Add correct host key in /Users/------/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /Users/------/.ssh/known_hosts:43
ECDSA host key for -------------------- has changed and you have requested strict checking.
Host key verification failed.

解決策

リモートの情報が変わってしまったので、古い情報はknown_hostsから消して、新しい情報を加えれば良さそう。
[]の部分を自分の場合に置き換えて実行。
例:hostname = "HOST" の場合、ssh-keygen -R "HOST"みたいな感じで

まずは古い情報を削除

ssh-keygen -R [hostname]
ssh-keygen -R [ip_address]
ssh-keygen -R [hostname],[ip_address]

-R hostname
Removes all keys belonging to hostname from a known_hosts file. This option is useful to delete hashed hosts (see the -H option above).

https://linux.die.net/man/1/ssh-keygen より
その後新しい情報を加えれば大丈夫そう。

ssh-keyscan -H [hostname],[ip_address] >> ~/.ssh/known_hosts
ssh-keyscan -H [ip_address] >> ~/.ssh/known_hosts
ssh-keyscan -H [hostname] >> ~/.ssh/known_hosts

参考

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?