linux
公開鍵認証でsshを多段接続するときはエージェントフォワードを使うと便利だ。
[user@local ~] ssh -A hosta [user@hosta ~] ssh hostbのようにするとhostaに秘密鍵をおいていなくても、sshが内部的に認証情報を転送することで hostbに公開鍵ログインすることができる。
ところがある日普段のように多段sshをしようとすると2段目で
[user@local ~] ssh -A hosta [user@hosta ~] ssh hostb Permission denied (publickey).のようにssh permission denied (publickey) にて認証失敗するようになった。
思い当たることがなかったのでしばらく調べると1段目の時点ですでに
[user@local ~] ssh -A hosta @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ 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 **:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**. Please contact your system administrator. Add correct host key in /home/user/.ssh/known_hosts to get rid of this message. Offending RSA key in /home/user/.ssh/known_hosts:133 RSA host key for example.com has changed and you have requested strict checking. Host key verification failed. [user@hosta ~] ssh hostb Permission denied (publickey).のように警告が出ていた。
これはhostaがアドレスは変わっていないのに別のサーバに置き換わっていることを警告するものだ。 「サーバが誰かにすり替えられていたら大変だからagent forwardingは無効にしておいたよ」 的なことを言っているらしい。
本当にセキュリティ上の脅威がある場合もあるだろうが、
思い返すと今回はそういえばhostaを初期化した後だった。
そこで以前接続時のホスト情報を削除して警告を消すことにする。
~/.ssh/known_hostsを手で削除してもよいのだが、ssh-keygenコマンド経由で消すのが本式のやり方らしい。
[user@local ~] ssh-keygen -R hosta [user@local ~] ssh -A hosta The authenticity of host 'hosta (???.???.???.???)' can't be established. RSA key fingerprint is ?????????????????????????????????????????????. Are you sure you want to continue connecting (yes/no)? yesでyesと答えると以後警告がなくなり、エージェントフォワーディングも成功するようになった。