ssh-keygen

Linux · Network · reference only

What it does

Generates and manages SSH keys to authenticate without a password. It creates a pair: a private key, which you keep, and a public key, which you copy to the server.

Syntax

ssh-keygen [opciones]

Options and parameters

  • -t tipo

    Key type: ed25519 (recommended), rsa, ecdsa.

  • -b bits

    Key size in bits, for example 4096 for RSA.

  • -C comentario

    Label stored in the public key, such as an email or a host name.

  • -f fichero

    Path where the private key is saved.

  • -N frase

    Passphrase that protects the key; empty for none.

  • -l

    Shows a key's fingerprint.

  • -p

    Changes the passphrase of an existing key.

  • -R equipo

    Removes that host's entries from known_hosts.

Usage examples

  • ssh-keygen -t ed25519

    Creates an ed25519 key pair in ~/.ssh/ after asking for the path and a passphrase.

  • ssh-keygen -t ed25519 -C "ana@portatil" -f ~/.ssh/id_trabajo

    Creates a key with a comment and a custom name.

  • ssh-keygen -l -f ~/.ssh/id_ed25519.pub

    Shows your public key's fingerprint.

  • ssh-keygen -R servidor.example.com

    Deletes the old known_hosts entry when the server changed its key.

Notes and common mistakes

  • Never share the private key (no extension); only the public one (.pub) is copied to the server, for example with ssh-copy-id.
  • The private key must have permissions 600 or ssh will reject it.

Related commands