Skip to content

Instantly share code, notes, and snippets.

@kurtis318
Created August 29, 2018 13:48
Show Gist options
  • Save kurtis318/fe0deb4f4d2019a04c326be1cdd0faaf to your computer and use it in GitHub Desktop.
Save kurtis318/fe0deb4f4d2019a04c326be1cdd0faaf to your computer and use it in GitHub Desktop.
Bad keys in known_hosts file

Issue

Every so often the ssh keys of a server is changed usually due to re-installation of the OS. Deleting the offending entries in the .ssh/known_hosts file will fix this. There are multple ways to do this.

Solutions

sed command

The following sed command is what I normally use. The only problem is that there might be more lines in the file than the one at line 22. Doing a grep on the hostname in known_hosts will identify more line.

  sed -ie "22d" .ssh/known_hosts

ssh-keygen command

  ssh-keygen -R somesite.someserver.org -f /home/joec/.ssh/known_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment