Linux "ssh-keygen" Command Line Options and Examples
authentication key generation, management and conversion

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.


ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa] [-N new_passphrase] [-C comment] [-f output_keyfile]
ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
ssh-keygen -i [-m key_format] [-f input_keyfile]
ssh-keygen -e [-m key_format] [-f input_keyfile]
ssh-keygen -y [-f input_keyfile]
ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile]
ssh-keygen -l [-v] [-E fingerprint_hash] [-f input_keyfile]
ssh-keygen -B [-f input_keyfile]
ssh-keygen -D pkcs11
ssh-keygen -F hostname [-f known_hosts_file] [-l]
ssh-keygen -H [-f known_hosts_file]
ssh-keygen -R hostname [-f known_hosts_file]
ssh-keygen -r hostname [-f input_keyfile] [-g]
ssh-keygen -G output_file [-v] [-b bits] [-M memory] [-S start_point]
ssh-keygen -T output_file -f input_file [-v] [-a rounds] [-J num_lines] [-j start_line] [-K checkpt]
[-W generator]
ssh-keygen -s ca_key -I certificate_identity [-h] [-U] [-D pkcs11_provider] [-n principals] [-O option]
[-V validity_interval] [-z serial_number] file ...
ssh-keygen -L [-f input_keyfile]
ssh-keygen -A [-f prefix_path]
ssh-keygen -k -f krl_file [-u] [-s ca_public] [-z version_number] file ...
ssh-keygen -Q -f krl_file file ...

Command Line Options:

When saving a new-format private key (i.e. an ed25519 key or when the -o flag is set), this option spec‐ifies the number of KDF (key derivation function) rounds used. Higher numbers result in slowerpassphrase verification and increased resistance to brute-force password cracking (should the keys bestolen).When screening DH-GEX candidates (using the -T command). This option specifies the number of primalitytests to perform.
ssh-keygen -a ...
Show the bubblebabble digest of specified private or public key file.
ssh-keygen -B ...
Specifies the number of bits in the key to create. For RSA keys, the minimum size is 1024 bits and thedefault is 2048 bits. Generally, 2048 bits is considered sufficient. DSA keys must be exactly 1024bits as specified by FIPS 186-2. For ECDSA keys, the -b flag determines the key length by selectingfrom one of three elliptic curve sizes: 256, 384 or 521 bits. Attempting to use bit lengths other thanthese three values for ECDSA keys will fail. Ed25519 keys have a fixed length and the -b flag will beignored.
ssh-keygen -b ...
Provides a new comment.
ssh-keygen -C ...
Download the RSA public keys provided by the PKCS#11 shared library pkcs11. When used in combinationwith -s, this option indicates that a CA key resides in a PKCS#11 token (see the CERTIFICATES sectionfor details).
ssh-keygen -D ...
Specifies the hash algorithm used when displaying key fingerprints. Valid options are: “md5” and“sha256”. The default is “sha256”.
ssh-keygen -E ...
Search for the specified hostname in a known_hosts file, listing any occurrences found. This option isuseful to find hashed host names or addresses and may also be used in conjunction with the -H option toprint found keys in a hashed format.
ssh-keygen -F ...
Specifies the filename of the key file.
ssh-keygen -f ...
Generate candidate primes for DH-GEX. These primes must be screened for safety (using the -T option)before use.
ssh-keygen -G ...
Use generic DNS format when printing fingerprint resource records using the -r command.
ssh-keygen -g ...
Specify the key identity when signing a public key. Please see the CERTIFICATES section for details.
ssh-keygen -I ...
Exit after screening the specified number of lines while performing DH candidate screening using the -Toption.
ssh-keygen -J ...
Start screening at the specified line number while performing DH candidate screening using the -Toption.
ssh-keygen -j ...
Write the last line processed to the file checkpt while performing DH candidate screening using the -Toption. This will be used to skip lines in the input file that have already been processed if the jobis restarted.
ssh-keygen -K ...
Prints the contents of one or more certificates.
ssh-keygen -L ...
Specify the amount of memory to use (in megabytes) when generating candidate moduli for DH-GEX.
ssh-keygen -M ...
Specify a key format for the -i (import) or -e (export) conversion options. The supported key formatsare: “RFC4716” (RFC 4716/SSH2 public or private key), “PKCS8” (PEM PKCS8 public key) or “PEM” (PEM pub‐lic key). The default conversion format is “RFC4716”.
ssh-keygen -m ...
Provides the new passphrase.
ssh-keygen -N ...
Specify one or more principals (user or host names) to be included in a certificate when signing a key.Multiple principals may be specified, separated by commas. Please see the CERTIFICATES section fordetails.
ssh-keygen -n ...
Specify a certificate option when signing a key. This option may be specified multiple times. See alsothe CERTIFICATES section for further details. The options that are valid for user certificates are:clear Clear all enabled permissions. This is useful for clearing the default set of permissions sopermissions may be added individually.critical:name[=contents]extension:name[=contents]Includes an arbitrary certificate critical option or extension. The specified name shouldinclude a domain suffix, e.g. “”. If contents is specified then it is includedas the contents of the extension/option encoded as a string, otherwise the extension/option iscreated with no contents (usually indicating a flag). Extensions may be ignored by a client orserver that does not recognise them, whereas unknown critical options will cause the certificateto be refused.At present, no standard options are valid for host keys.force-command=commandForces the execution of command instead of any shell or command specified by the user when thecertificate is used for ssh-agent(1) forwarding (permitted by default).no-port-forwardingDisable port forwarding (permitted by default).no-pty Disable PTY allocation (permitted by default).no-user-rcDisable execution of ~/.ssh/rc by sshd(8) (permitted by default).no-x11-forwardingDisable X11 forwarding (permitted by default).permit-agent-forwardingAllows ssh-agent(1) forwarding.permit-port-forwardingAllows port forwarding.permit-ptyAllows PTY allocation.permit-user-rcAllows execution of ~/.ssh/rc by sshd(8).permit-x11-forwardingAllows X11 forwarding.source-address=address_listRestrict the source addresses from which the certificate is considered valid. The address_listis a comma-separated list of one or more address/netmask pairs in CIDR format.
ssh-keygen -O ...
Provides the (old) passphrase.
ssh-keygen -P ...
Test whether keys have been revoked in a KRL.
ssh-keygen -Q ...
Silence ssh-keygen.
ssh-keygen -q ...
Removes all keys belonging to hostname from a known_hosts file. This option is useful to delete hashedhosts (see the -H option above).
ssh-keygen -R ...
Print the SSHFP fingerprint resource record named hostname for the specified public key file.
ssh-keygen -r ...
Specify start point (in hex) when generating candidate moduli for DH-GEX.
ssh-keygen -S ...
Certify (sign) a public key using the specified CA key. Please see the CERTIFICATES section fordetails.When generating a KRL, -s specifies a path to a CA public key file used to revoke certificates directlyby key ID or serial number. See the KEY REVOCATION LISTS section for details.
ssh-keygen -s ...
Test DH group exchange candidate primes (generated using the -G option) for safety.
ssh-keygen -T ...
Specifies the type of key to create. The possible values are “dsa”, “ecdsa”, “ed25519”, or “rsa”.
ssh-keygen -t ...
Specify a validity interval when signing a certificate. A validity interval may consist of a singletime, indicating that the certificate is valid beginning now and expiring at that time, or may consistof two times separated by a colon to indicate an explicit time interval. The start time may be speci‐fied as a date in YYYYMMDD format, a time in YYYYMMDDHHMMSS format or a relative time (to the currenttime) consisting of a minus sign followed by a relative time in the format described in the TIME FORMATSsection of sshd_config(5). The end time may be specified as a YYYYMMDD date, a YYYYMMDDHHMMSS time or arelative time starting with a plus character.For example: “+52w1d” (valid from now to 52 weeks and one day from now), “-4w:+4w” (valid from fourweeks ago to four weeks from now), “20100101123000:20110101123000” (valid from 12:30 PM, January 1st,2010 to 12:30 PM, January 1st, 2011), “-1d:20110101” (valid from yesterday to midnight, January 1st,2011).
ssh-keygen -V ...
Specify desired generator when testing candidate moduli for DH-GEX.
ssh-keygen -W ...
This option will read a private OpenSSH format file and print an OpenSSH public key to stdout.
ssh-keygen -y ...
Specifies a serial number to be embedded in the certificate to distinguish this certificate from othersfrom the same CA. The default serial number is zero.When generating a KRL, the -z flag is used to specify a KRL version number.MODULI GENERATIONssh-keygen may be used to generate groups for the Diffie-Hellman Group Exchange (DH-GEX) protocol. Generatingthese groups is a two-step process: first, candidate primes are generated using a fast, but memory intensiveprocess. These candidate primes are then tested for suitability (a CPU-intensive process).Generation of primes is performed using the -G option. The desired length of the primes may be specified by the
ssh-keygen -z ...