/mili

Script for Removing Changed Host Identification

As I am working as a system administer this days and always had a problem with changing Remote Identification of servers, I write simple script which you can delete a line from your ~/.ssh/known_hosts


#!/bin/bash
#rm_known_hosts bash script
tmp_head=$(mktemp)
tmp_tail=$(mktemp)
tmp_dest=$(mktemp)

file_name="$HOME/.ssh/known_hosts"
line_nums=$(cat $file_name | wc -l )

cat $file_name | head -n`echo "$1 -1 " | bc ` > $tmp_head
cat $file_name | tail -n`echo "$line_nums - $1 "| bc` > $tmp_tail

cat $tmp_head > $tmp_dest
cat $tmp_tail >> $tmp_dest

cp $tmp_dest $file_name

#remove tmps
rm -f $tmp_head
rm -f $tmp_tail
rm -f $tmp_dest


for example run when you got error like this :

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
ac:2c:99:de:a6:f4:7d:4a:81:93:7e:9c:67:a6:14:45.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:90
RSA host key for 10.10.10.10 has changed and you have requested strict checking.
Host key verification failed.


you just run

./rm_known_hosts 90

Life will be essayer with tiny scripts !