Skip to content

Instantly share code, notes, and snippets.

@flores
Created March 15, 2011 06:33
Show Gist options
  • Save flores/870396 to your computer and use it in GitHub Desktop.
Save flores/870396 to your computer and use it in GitHub Desktop.
Use sed to reduce known_hosts pain
### The pain after a host is updated:
lo@padlet:~/someproject$ git pull
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: POSSIBLE DNS SPOOFING DETECTED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for repo.somedomain.com has changed,
and the key for the corresponding IP address x.x.x.x
is unchanged. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
Offending key for IP in /home/lo/.ssh/known_hosts:568
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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
SO:ME:FI:NG:ER:PR:IN:T!
Please contact your system administrator.
Add correct host key in /home/lo/.ssh/known_hosts to get rid of this message.
Offending RSA key in /home/lo/.ssh/known_hosts:85
RSA host key for repo.somedomain.com has changed and you have requested strict checking.
Host key verification failed.
fatal: The remote end hung up unexpectedly
# Notice lines 568 and 85 above. Going top to bottom...
lo@padlet:~/someproject$ sed -i 568d ~/.ssh/known_hosts
lo@padlet:~/someproject$ sed -i 85d ~/.ssh/known_hosts
# No pain
lo@padlet:~/someproject$ git pull
The authenticity of host 'repo.somedomain.com (x.x.x.x)' can't be established.
RSA key fingerprint is SO:ME:FI:NG:ER:PR:IN:T!
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'repo.somedomain.com,x.x.x.x' (RSA) to the list of known hosts.
remote: Counting objects: 18, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 11 (delta 8), reused 0 (delta 0)
Unpacking objects: 100% (11/11), done.
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment