De man ssh-keygen (SSH-KEYGEN (1))
-R hostname Removes all keys belonging to hostname from a known_hosts file. This option is useful to delete hashed hosts (see the -H option above).
Tente isto:
ssh-keygen -R hostname [-f known_hosts_file]
Eu tenho um script que cria dinamicamente instâncias do Amazon EC2 e adiciona sua chave ssh ao meu ~ / .ssh / known_hosts. No entanto, sempre que preciso atualizar a instância finalizando e recriando, recebo mensagens de aviso desagradáveis como:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 ECDSA key sent by the remote host is
<fingerprint>.
Please contact your system administrator.
Add correct host key in ~/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in ~/.ssh/known_hosts:94
remove with: ssh-keygen -f "~/.ssh/known_hosts" -R <hostname>
Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
O aviso é compreensível, mas mesmo se eu executar esse comando para remover a chave antiga, o login ainda me dará o aviso:
Warning: Permanently added '<hostname>' (ECDSA) to the list of known hosts.
Warning: the ECDSA host key for '<hostname>' differs from the key for the IP address '<ip>'
Offending key for IP in ~/.ssh/known_hosts:96
A solução é remover manualmente essa linha no meu known_hosts , mas existe uma maneira de automatizar isso executando um único comando antes?
De man ssh-keygen (SSH-KEYGEN (1))
-R hostname Removes all keys belonging to hostname from a known_hosts file. This option is useful to delete hashed hosts (see the -H option above).
Tente isto:
ssh-keygen -R hostname [-f known_hosts_file]