3 pasos para realizar el inicio de sesión SSH sin contraseña

Con estos 3 sencillos pasos podrás iniciar sesión en un servidor Linux remoto sin introducir la contraseña. Usaremos ssky-keygen y ssh-copy-id.

    1. Generamos nuestras claves privadas y publicas con el comando 'ssh-keygen'. Si ya teniamos estas claves generadas nos preguntará si deseamos sobrescribirlas, en nuestro caso y como ejemplo, sobrescribimos las claves.
    2. Nos preguntará 2 veces sobre la 'frase clave', la dejamos en blanco.
    3. Copiamos las clave generada (la pública) al servidor remoto con el comando 'ssh-copy-id'
      1. Nos pedira la clave del usuario remoto. La introducimos.
    4. Por último si todo ha ido bien podremos conectarnos mediante ssh al equipo remoto sin introducir la contraseña.

 En el siguiente vídeo podréis ver el proceso completo:


A continuación un ejemplo del proceso completo:

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (~/.ssh/id_rsa):
~/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in ~/.ssh/id_rsa
Your public key has been saved in ~/.ssh/id_rsa.pub
The key fingerprint is:
SHA256: hash_of_key localhost
The key's randomart image is:
+---[RSA 3072]----+

+----[SHA256]-----+

$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote_user@remote_host
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "~/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
remote_user@remote_host's password: remote_user_password

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'remote_user@remote_host'"
and check to make sure that only the key(s) you wanted were added.

$ ssh remote_user@remote_host

Publicar un comentario

0 Comentarios