LoginSignup
6
5

More than 5 years have passed since last update.

ERROR: Net::SSH::HostKeyMismatch: fingerprint を一発解決するコマンドを作る

Posted at
ERROR: Net::SSH::HostKeyMismatch: fingerprint xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx does not match for "xxx.xxx.xxx.xxx"

IP一緒だけど、サーバー自体は入れ替わってる場合などまあまあある。
known_hosts をIPで検索して、その行削除すれば直るけど、
週に何度も起こったときにカッとなってやった。

forget_host.sh
#/bin/bash

if [ $# -ne 1 ]; then
  echo "[error] specify host"
  exit 1
fi

host=`echo $1 | sed 's/\./\\\./g'`
sed -i '' "/${host}/d" ~/.ssh/known_hosts
echo "forget $1"

known_hostsから忘れたいIPを指定してこんな感じで呼べる
./forget_host.sh 55.55.55.55

なお、Mac OS 10.9.5では動作確認している。
Linuxの種類によってsedが微妙に仕様が違うっぽいので要注意です。

6
5
3

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
6
5