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 tipoKey type: ed25519 (recommended), rsa, ecdsa.
-b bitsKey size in bits, for example 4096 for RSA.
-C comentarioLabel stored in the public key, such as an email or a host name.
-f ficheroPath where the private key is saved.
-N frasePassphrase that protects the key; empty for none.
-lShows a key's fingerprint.
-pChanges the passphrase of an existing key.
-R equipoRemoves that host's entries from known_hosts.
Usage examples
ssh-keygen -t ed25519Creates an ed25519 key pair in ~/.ssh/ after asking for the path and a passphrase.
ssh-keygen -t ed25519 -C "ana@portatil" -f ~/.ssh/id_trabajoCreates a key with a comment and a custom name.
ssh-keygen -l -f ~/.ssh/id_ed25519.pubShows your public key's fingerprint.
ssh-keygen -R servidor.example.comDeletes 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.