Skip to content

Instantly share code, notes, and snippets.

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 refo/6987a51a314481d33c83914b93bbae1c to your computer and use it in GitHub Desktop.
Save refo/6987a51a314481d33c83914b93bbae1c to your computer and use it in GitHub Desktop.
Warning: remote host identification has changed
#!/usr/bin/env sh
HOST=$1
ssh-keygen -R "${HOST}"
ssh-keyscan -H "${HOST}" >> ~/.ssh/known_hosts

Remove the host from known_hosts

If you trust the server and already know that server fingerprint changed due to re-install for example; you could just remove the previous identification from the known_hosts file.

ssh-keygen -R "remote.host.ip"

You can then add the new fingerprint if you don't want ssh to prompt you to do so.

ssh-keyscan -H remote.host.ip >> ~/.ssh/known_hosts

Automate the process

If you would like to automate this process, a simple shell script could ease the task

#!/usr/bin/env sh

HOST=$1

ssh-keygen -R "${HOST}"
ssh-keyscan -H "${HOST}" >> ~/.ssh/known_hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment