martes, 3 de abril de 2012

SSH: Eliminando claves erróneas del fichero known_hosts

Otro recordatorio para mi memoria de pez.

Debian almacena las claves públicas de los hosts a los que se conecta en el fichero

/home/usuario/.ssh/known_hosts

En ocasiones, la clave pública de un ordenador puede cambiar. Por ejemplo, porque hayamos trasladado el servidor. En esos casos, SSH se negará a conectarse al servidor nuevo porque su clave pública actual no coincidirá con la antigua. Lo hará con un mensaje apocalíptico:



@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The RSA host key for ftp.xxxxx.es 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/jose/.ssh/known_hosts:18
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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 the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
6f:16:ff:ce:2f:30:15:86:d8:69:dd:6c:c7:fe:21:0c.
Please contact your system administrator.
Add correct host key in /home/jose/.ssh/known_hosts to get rid of this message.
Offending key in /home/jose/.ssh/known_hosts:11
RSA host key for ftp.xxxxx.es has changed and you have requested strict checking.
Host key verification failed.
lost connection

Bueno, pues hay tres formas de arreglar ésto:

a- Configurando SSH para que no haga un chequeo estricto de claves. No es aconsejable, por motivos de seguridad.

b- Borrando el fichero known_hosts. Tampoco es aconsejable por motivos de seguridad, y encima cada vez que te conectes a tus servidores te volverá a preguntar si quieres confiar en la clave pública. Un coñazo.

c- Usar ssh-keygen para eliminar sólo la clave problemática en el fichero known_hosts :

jose@jose:~$ ssh-keygen -R "ftp.xxxxx.es"
/home/jose/.ssh/known_hosts updated.
Original contents retained as /home/jose/.ssh/known_hosts.old

Fin del problema.

No hay comentarios:

Publicar un comentario