Skip to content

Instantly share code, notes, and snippets.

@thecubic
Created May 15, 2014 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecubic/c17140d62f1ddf8b010a to your computer and use it in GitHub Desktop.
Save thecubic/c17140d62f1ddf8b010a to your computer and use it in GitHub Desktop.
deletes specific line(s) from known_hosts
#!/bin/bash
# Problem:
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# @ 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
# ce:ed:2d:9a:9b:90:50:74:f5:48:88:56:10:c1:dd:d4.
# Please contact your system administrator.
# Add correct host key in /home/thecubic/.ssh/known_hosts to get rid of this message.
# Offending RSA key in /home/thecubic/.ssh/known_hosts:889
# Password authentication is disabled to avoid man-in-the-middle attacks.
# Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
# X11 forwarding is disabled to avoid man-in-the-middle attacks.
# Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
# Warning: Permanently added 'gibson' (RSA) to the list of known hosts.
# Warning: the RSA host key for 'gibson' differs from the key for the IP address '10.216.17.99'
# Offending key for IP in /home/thecubic/.ssh/known_hosts:884
# Solution:
# khdel 884 889
for i in $(for i in "$@"; do echo $i; done | sort -rn | uniq); do echo ${i}d ; done | sed -i.bak -f - ~/.ssh/known_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment