ssh-keygen
Quick Reference
Command Name:
ssh-keygen
Category:
networking
Platform:
Linux/Unix/Windows
Basic Usage:
Common Use Cases
- 1
Key generation
Create public/private key pairs for passwordless SSH authentication
- 2
Key management
Manage, convert, and examine SSH keys and their properties
- 3
Certificate management
Create and manage SSH certificates for scalable authentication
- 4
Host verification
Manage and verify SSH host keys to prevent man-in-the-middle attacks
Syntax
ssh-keygen [options]
Options
Option | Description |
---|---|
-a num | Number of KDF (Key Derivation Function) rounds |
-b bits | Specify the number of bits in the key |
-C comment | Add a comment to the key |
-e | Export OpenSSH key to RFC4716 format |
-f filename | Specify the filename of the key file |
-F hostname | Search for hostname in known_hosts file |
-H | Hash hostnames in known_hosts file |
-i | Import key from RFC4716 format |
-l | Show fingerprint of key file |
-m key_format | Key format: PEM, PKCS8, RFC4716 |
-N new_passphrase | Provide new passphrase |
-p | Change passphrase of private key file |
-P passphrase | Provide old passphrase |
-q | Quiet mode |
-R hostname | Remove host from known_hosts file |
-t type | Specify key type (rsa, dsa, ecdsa, ed25519) |
-v | Verbose mode |
-y | Read private key file and print public key |
Certificate Options:
Option | Description |
---|---|
-I certificate_id | Identity string for certificate |
-n principals | Principals (users/hosts) for certificate |
-O option | Specify certificate options |
-s ca_key | CA (Certificate Authority) key for signing |
-V validity | Specify certificate validity period |
-z serial | Specify serial number for certificate |
Examples
How to Use These Examples
The examples below show common ways to use the ssh-keygen
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Key Generation:
ssh-keygen
Generate a new SSH key pair with default settings (RSA, 2048 bits).
ssh-keygen -t ed25519
Generate a more secure Ed25519 key (recommended for new deployments).
ssh-keygen -t rsa -b 4096
Generate an RSA key with 4096 bits for stronger security.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Add a comment to the key for easier identification.
ssh-keygen -f ~/.ssh/mykey
Specify a custom filename and path for the key pair.
Key Management:
ssh-keygen -l -f ~/.ssh/id_rsa.pub
Display the fingerprint of a public key.