Thursday, May 10, 2012

Delete conflicts in known_hosts

Often times i will connect to an ssh server in one network and so some work. Later on, I will move somewhere else and connect to some other network and have to ssh in. Incidentily i'm ssh'ing into two different servers that happen to have the same IP (even though they are two completely different networks). I know whats going on here and i'm doing it all on purpose. Unfortunately ssh still likes to freak out that this IP now magically has a new public key. cool story bro, i already knew.


I got sick of every time this happened to have to go into known_hosts and delete that entry. ssh will always tell you the line number that contains the conflicting key, so all i have to do is delete that line from known_hosts and bam. i'm done.  So i came up with this little function to make my life easier:



ssh-del-line() {


    if [[ -z $1 ]]; then


        echo 'Deletes the specified linenumber from ~/.ssh/known_hosts'


        echo 'Usage: ssh-del-line linenumber'


    else


        sed -i "/$1/d" ~/.ssh/known_hosts


    fi; }



No comments:

Post a Comment