ssh-keygen generates, manages and converts
authentication keys for ssh(1). ssh-keygen can create keys for use by
SSH protocol version 2.
The type of key to be generated is specified with the
-t option. If invoked without any arguments,
ssh-keygen will generate an Ed25519 key.
ssh-keygen is also used to generate groups
for use in Diffie-Hellman group exchange (DH-GEX). See the
MODULI GENERATION section for
details.
Finally, ssh-keygen can be used to
generate and update Key Revocation Lists, and to test whether given keys
have been revoked by one. See the
KEY REVOCATION LISTS section
for details.
Normally each user wishing to use SSH with public key
authentication runs this once to create the authentication key in
~/.ssh/id_ecdsa,
~/.ssh/id_ecdsa_sk,
~/.ssh/id_ed25519,
~/.ssh/id_ed25519_sk,
~/.ssh/id_mldsa44_ed25519 or
~/.ssh/id_rsa. Additionally, the system
administrator may use this to generate host keys, as seen in
/etc/rc.
Normally this program generates the key and asks for a file in
which to store the private key. The public key is stored in a file with the
same name but “.pub” appended. The program also asks for a
passphrase. The passphrase may be empty to indicate no passphrase (host keys
must have an empty passphrase), or it may be a string of arbitrary length. A
passphrase is similar to a password, except it can be a phrase with a series
of words, punctuation, numbers, whitespace, or any string of characters you
want. Good passphrases are 10-30 characters long, are not simple sentences
or otherwise easily guessable (English prose has only 1-2 bits of entropy
per character, and provides very bad passphrases), and contain a mix of
upper and lowercase letters, numbers, and non-alphanumeric characters. The
passphrase can be changed later by using the -p
option.
There is no way to recover a lost passphrase. If the passphrase is
lost or forgotten, a new key must be generated and the corresponding public
key copied to other machines.
ssh-keygen will by default write keys in
an OpenSSH-specific format. This format is preferred as it offers better
protection for keys at rest as well as allowing storage of key comments
within the private key file itself. The key comment may be useful to help
identify the key. The comment is initialized to “user@host”
when the key is created, but can be changed using the
-c option.
It is still possible for ssh-keygen to
write the previously-used PEM format private keys using the
-m flag. This may be used when generating new keys,
and existing new-format keys may be converted using this option in
conjunction with the -p (change passphrase)
flag.
After a key is generated, ssh-keygen will
ask where the keys should be placed to be activated.
The options are as follows:
-A
- Generate host keys of all default key types (rsa, ecdsa, mldsa44-ed25519
and ed25519) if they do not already exist. The host keys are generated
with the default key file path, an empty passphrase, default bits for the
key type, and default comment. If
-f has also been
specified, its argument is used as a prefix to the default path for the
resulting host key files. This is used by /etc/rc
to generate new host keys.
-a
rounds
- When saving a private key, this option specifies the number of KDF (key
derivation function, currently
bcrypt_pbkdf(3)) rounds used. Higher numbers result in slower
passphrase verification and increased resistance to brute-force password
cracking (should the keys be stolen). The default is 16 rounds.
-B
- Show the bubblebabble digest of specified private or public key file.
-b
bits
- Specifies the number of bits in the key to create. For RSA keys, the
minimum size is 1024 bits and the default is 3072 bits. Generally, 3072
bits is considered sufficient. For ECDSA keys, the
-b flag determines the key length by selecting
from one of three elliptic curve sizes: 256, 384 or 521 bits. Attempting
to use bit lengths other than these three values for ECDSA keys will fail.
ECDSA-SK, Ed25519 and Ed25519-SK keys have a fixed length and the
-b flag will be ignored.
-C
comment
- Provides a new comment.
-c
- Requests changing the comment in the private and public key files. The
program will prompt for the file containing the private keys, for the
passphrase if the key has one, and for the new comment.
-D
pkcs11
- Download the public keys provided by the PKCS#11 shared library
pkcs11. When used in combination with
-s, this option indicates that a CA key resides in
a PKCS#11 token (see the
CERTIFICATES section for
details).
-E
fingerprint_hash
- Specifies the hash algorithm used when displaying key fingerprints. Valid
options are: “md5” and “sha256”. The default
is “sha256”.
-e
- This option will read a private or public OpenSSH key file and print to
stdout a public key in one of the formats specified by the
-m option. The default export format is
“RFC4716”. This option allows exporting OpenSSH keys for use
by other programs, including several commercial SSH implementations.
-F
hostname | [hostname]:port
- Search for the specified hostname (with optional
port number) in a known_hosts file, listing any
occurrences found. This option is useful to find hashed host names or
addresses and may also be used in conjunction with the
-H option to print found keys in a hashed
format.
-f
filename
- Specifies the filename of the key file.
-g
- Use generic DNS format when printing fingerprint resource records using
the
-r command.
-H
- Hash a known_hosts file. This replaces all
hostnames and addresses with hashed representations within the specified
file; the original content is moved to a file with a .old suffix. These
hashes may be used normally by
ssh and
sshd, but they do not reveal identifying
information should the file's contents be disclosed. This option will not
modify existing hashed hostnames and is therefore safe to use on files
that mix hashed and non-hashed names.
-h
- When signing a key, create a host certificate instead of a user
certificate. See the CERTIFICATES
section for details.
-I
certificate_identity
- Specify the key identity when signing a public key. See the
CERTIFICATES section for
details.
-i
- This option will read an unencrypted private (or public) key file in the
format specified by the
-m option and print an
OpenSSH compatible private (or public) key to stdout. This option allows
importing keys from other software, including several commercial SSH
implementations. The default import format is
“RFC4716”.
-K
- Download resident keys from a FIDO authenticator. Public and private key
files will be written to the current directory for each downloaded key. If
multiple FIDO authenticators are attached, keys will be downloaded from
the first touched authenticator. See the
FIDO AUTHENTICATOR section
for more information.
-k
- Generate a KRL file. In this mode,
ssh-keygen will
generate a KRL file at the location specified via the
-f flag that revokes every key or certificate
presented on the command line. Keys/certificates to be revoked may be
specified by public key file or using the format described in the
KEY REVOCATION LISTS
section.
-L
- Prints the contents of one or more certificates.
-l
- Show fingerprint of specified public key file.
ssh-keygen will try to find the matching public
key file and prints its fingerprint. If combined with
-v, a visual ASCII art representation of the key
is supplied with the fingerprint.