SSH-KEYGEN(1)
โจ ssh-keygen โจ
okay bestie, welcome to ssh-keygen โ that's the OpenSSH authentication key utility, and it lives in the General Commands Manual, section 1. it's giving the key-making tool. the one. periodt. ๐
๐ฆ SYNOPSIS ๐ฆ
so here's the vibe โ ssh-keygen has a lot of modes, and each one is its own little synopsis line. copy these exactly, no cap:
ssh-keygen [-q] [-a rounds] [-b bits] [-C comment] [-f output_keyfile]
[-m format] [-N new_passphrase] [-O option]
[-t ecdsa | ecdsa-sk | ed25519 | ed25519-sk | mldsa44-ed25519 | rsa]
[-w provider] [-Z cipher]
ssh-keygen -p [-a rounds] [-f keyfile] [-m format] [-N new_passphrase]
[-P old_passphrase] [-Z cipher]
ssh-keygen -i [-f input_keyfile] [-m key_format]
ssh-keygen -e [-f input_keyfile] [-m key_format]
ssh-keygen -y [-f input_keyfile]
ssh-keygen -c [-a rounds] [-C comment] [-f keyfile] [-P passphrase]
ssh-keygen -l [-v] [-E fingerprint_hash] [-f input_keyfile]
ssh-keygen -B [-f input_keyfile]
ssh-keygen -D pkcs11
ssh-keygen -F hostname [-lv] [-f known_hosts_file]
ssh-keygen -H [-f known_hosts_file]
ssh-keygen -K [-a rounds] [-w provider]
ssh-keygen -R hostname [-f known_hosts_file]
ssh-keygen -r hostname [-g] [-f input_keyfile]
ssh-keygen -M generate [-O option] output_file
ssh-keygen -M screen [-f input_file] [-O option] output_file
ssh-keygen -I certificate_identity -s ca_key [-hU] [-D pkcs11_provider]
[-n principals] [-O option] [-V validity_interval]
[-z serial_number] file ...
ssh-keygen -L [-f input_keyfile]
ssh-keygen -A [-a rounds] [-f prefix_path]
ssh-keygen -k -f krl_file [-u] [-s ca_public] [-z version_number]
file ...
ssh-keygen -Q [-l] -f krl_file file ...
ssh-keygen -Y find-principals [-O option] -s signature_file -f
allowed_signers_file
ssh-keygen -Y match-principals -I signer_identity -f
allowed_signers_file
ssh-keygen -Y check-novalidate [-O option] -n namespace -s
signature_file
ssh-keygen -Y sign [-O option] -f key_file -n namespace file ...
ssh-keygen -Y verify [-O option] -f allowed_signers_file -I
signer_identity -n namespace -s signature_file
[-r revocation_file]
๐ธ DESCRIPTION ๐ธ
so ssh-keygen generates, manages and converts authentication keys for ssh(1). and yes, it can create keys for use by SSH protocol version 2. iconic behavior honestly. ๐
the type of key you wanna generate? that's the -t option's whole job. and if you just run it with no arguments at all, ssh-keygen will generate an Ed25519 key. default queen. โจ
ssh-keygen is also used to generate groups for use in Diffie-Hellman group exchange (DH-GEX). go peek at the โMODULI GENERATIONโ section for the deets. ๐ฆ
and finally โ yes there's a finally โ ssh-keygen can generate and update Key Revocation Lists, and test whether given keys have been revoked by one. see the โKEY REVOCATION LISTSโ section. it does it all fr fr.
okay so normally, every user who wants 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~/.ssh/id_rsa
and on top of that, the system administrator may use this to generate host keys, as seen in /etc/rc. sysadmins stay busy. ๐
so here's how the normal flow goes. this program generates the key and asks for a file in which to store the private key. the public key gets stored in a file with the same name but with โ.pubโ appended. cute little duo. ๐ซถ
then it also asks for a passphrase. the passphrase may be empty to indicate no passphrase โ and heads up, 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 literally any string of characters you want. the way that a passphrase can be a whole sentence is so much better than a password ngl.
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. ๐
and you can change the passphrase later by using the -p option. slay.
๐จ 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. so likeโฆ write it down bestie. ๐ญ
ssh-keygen will by default write keys in an OpenSSH-specific format. this format is preferred because it offers better protection for keys at rest and allows 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. so helpful honestly.
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. iykyk.
after a key is generated, ssh-keygen will ask where the keys should be placed to be activated. โจ
the options are as follows:
๐ OPTIONS ๐
-Aโ generate host keys of all default key types (rsa,ecdsa,mldsa44-ed25519anded25519) if they don't 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-fhas 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/rcto generate new host keys. ๐-arounds โ when saving a private key, this option specifies the number of KDF (key derivation function, currentlybcrypt_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 32 rounds. ๐ฅ-Bโ show the bubblebabble digest of the specified private or public key file. bubblebabble. that's the actual name. iconic. ๐ซง-bbits โ 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-bflag 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-bflag will be ignored. ๐-Ccomment โ 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. glow up your key's little nametag. โจ-Dpkcs11 โ 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). ๐-Efingerprint_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-moption. the default export format is โRFC4716โ. this option allows exporting OpenSSH keys for use by other programs, including several commercial SSH implementations. take your key on tour bestie ๐งณ-Fhostname | [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-Hoption to print found keys in a hashed format. ๐-ffilename โ specifies the filename of the key file. the moment of truth. ๐-gโ use generic DNS format when printing fingerprint resource records using the-rcommand. ๐-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.oldsuffix. these hashes may be used normally bysshandsshd, 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. so considerate honestly. ๐ซถ-hโ when signing a key, create a host certificate instead of a user certificate. see the โCERTIFICATESโ section for details. ๐-Icertificate_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-moption 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โ. reverse uno card ๐-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-fflag 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. it's giving consequences ๐-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. not me getting a whole portrait of my key ๐ญ๐จ-Mgenerate โ generate candidate Diffie-Hellman Group Exchange (DH-GEX) parameters for eventual use by the โdiffie-hellman-group-exchange-*โ key exchange methods. the numbers generated by this operation must be further screened before use. see the โMODULI GENERATIONโ section for more information. ๐งฎ
(more coming bestie, don't go anywhere ๐)
-M screenโ screening time for the Diffie-Hellman Group Exchange candidates, bestie</p> ๐ This one takes a whole list of candidate numbers and vibe-checks them: are they safe (Sophie Germain) primes, and do they have acceptable group generators? Whatever comes out of this lil operation can get yeeted into the/etc/ssh/modulifile. More deets in the โMODULI GENERATIONโ section, go look ๐-m key_formatโ pick your key format โจ This applies to key generation, to the-i(import) and-e(export) conversion options, and to the-pchange-passphrase operation. That last one can be used to convert between OpenSSH private key and PEM private key formats, no cap. The formats that are supported are:
By default, OpenSSH writes newly-generated private keys in its own format, but when you're converting public keys for export, the default format is RFC4716. And heads up: if you set the format to PEM while generating or updating a supported private key type, the key gets stored in the legacy PEM private key format. Legacy, bestie. We're in vintage territory ๐ซ
-N new_passphraseโ hands over the new passphrase ๐ That's it, that's the whole thing.-n principalsโ list the principal(s) โ those are user or host names โ that should be included in a certificate when you're signing a key. You can list multiple principals, just separate them with commas. The โCERTIFICATESโ section has the full lore ๐-O optionโ a key/value option, ooooh ๐ These are specific to whatever operation you askedssh-keygento do, so which ones apply depends entirely on the mission.
When you're signing certificates, you can specify one of the options listed in the โCERTIFICATESโ section right here.
When you're doing moduli generation or screening, you can specify one of the options listed in the โMODULI GENERATIONโ section.
When you're generating FIDO authenticator-backed keys, the options listed in the โFIDO AUTHENTICATORโ section may be specified.
When you're changing the passphrase for an existing key, the options listed in the documentation for the -p flag may be used.
When you're doing signature-related options with the -Y flag, these are the ones that get accepted:
hashalg=algorithmโ picks the hash algorithm used for hashing the message that's about to be signed. Valid algorithms aresha256andsha512. The default issha512. ๐print-pubkeyโ prints the full public key to standard output after signature verification. Show me the key, show me the key ๐verify-time=timestampโ specifies a time to use when validating signatures instead of the current time. You can give the time as a date or time in theYYYYMMDD[Z]format or in theYYYYMMDDHHMM[SS][Z]format. Dates and times get interpreted in the current system time zone unless you slap aZcharacter on the end, which makes them get interpreted in the UTC time zone. ๐
When you're generating SSHFP DNS records from public keys using the -r flag, this one is accepted:
hashalg=algorithmโ picks a hash algorithm to use when printing SSHFP records using the-Dflag. Valid algorithms aresha1andsha256. The default is to print both. both, because why choose โจ
And the -O option can be specified multiple times, so stack 'em up bestie ๐ง
-P passphraseโ provides the (old) passphrase ๐ Yes, old. The one from before. The pre-glow-up passphrase.-pโ requests changing the passphrase of a private key file instead of creating a brand new private key. The program will prompt you for the file containing the private key, for the old passphrase, and twice for the new passphrase. Double-check energy, we love to see it ๐
Updating the passphrase causes encrypted keys to be reencrypted, which is lowkey a glow-up opportunity: it lets you change the cipher and/or the number of KDF rounds (that's the -Z and -a options respectively, iykyk).
This option can also be used to set or clear FIDO related options via the -O flag. These FIDO options can be modified:
touch-required/no-touch-requiredโ adds or removes the requirement that signatures made using this key include a demonstration of user presence (like, the user actually touching the authenticator). ๐verify-required/no-verify-requiredโ adds or removes the requirement for signatures made using this key to first verify the user identity, e.g. by PIN or on-token biometrics. ๐
-Qโ tests whether keys have been revoked in a KRL ๐ซ And if you also throw in the-loption, then the contents of the KRL get printed. Surprise bonus content ๐-qโ silencessh-keygen๐คซ Not a peep. Main character silence.-R hostname | [hostname]:portโ removes all keys belonging to the specified hostname (with an optional port number) from aknown_hostsfile. This one is genuinely useful for deleting hashed hosts โ see the-Hoption above. Bye bye, ghost of hosts past ๐-r hostnameโ prints the SSHFP fingerprint resource record named hostname for the specified public key file. ๐-s ca_keyโ certifies (signs) a public key using the specified CA key. The โCERTIFICATESโ section has the details.
When you're generating a KRL, -s instead specifies a path to a CA public key file used to revoke certificates directly by key ID or serial number. See the โKEY REVOCATION LISTSโ section for that whole situation. ๐
-t ecdsa | ecdsa-sk | ed25519 | ed25519-sk | mldsa44-ed25519 | rsaโ specifies the type of key to create ๐๏ธ The possible values areecdsa,ecdsa-sk,ed25519 (the default),ed25519-sk,mldsa44-ed25519orrsa. So yeah,ed25519is the default, and it's iconic for a reason โญ
This flag can also be used to specify the desired signature type when signing certificates using an RSA CA key. The available RSA signature variants are:
ssh-rsaโ SHA1 signatures, not recommended ๐rsa-sha2-256rsa-sha2-512โ the default for RSA keys ๐
-Uโ when used together with-sor-Y sign, this option indicates that a CA key resides in anssh-agent(1). See the โCERTIFICATESโ section for more info. Your key is in the agent, bestie, it's living its best life ๐ซถ-uโ update a KRL ๐ When specified with-k, the keys you list via the command line get added to the existing KRL rather than a whole new KRL being created. Growth mindset ๐ฑ-V validity_intervalโ specify a validity interval when signing a certificate โณ A validity interval can be a single time โ meaning the certificate is valid starting now and expires at that time โ or it can be two times separated by a colon, which indicates an explicit time interval. It's giving "from X to Y" energy.
The start time may be specified as:
- The string
always, to indicate the certificate has no specified start time. ๐ - A date or time in the system time zone formatted as
YYYYMMDDorYYYYMMDDHHMM[SS]. - A date or time in the UTC time zone as
YYYYMMDDZorYYYYMMDDHHMM[SS]Z. - A relative time before the current system time, consisting of a minus sign followed by an interval in the format described in the TIME FORMATS section of
sshd_config(5). - A raw seconds since epoch (Jan 1 1970 00:00:00 UTC) as a hexadecimal number beginning with
0x.
The end time may be specified similarly to the start time:
- The string
forever, to indicate the certificate has no specified end time. โพ๏ธ - A date or time in the system time zone formatted as
YYYYMMDDorYYYYMMDDHHMM[SS]. - A date or time in the UTC time zone as
YYYYMMDDZorYYYYMMDDHHMM[SS]Z. - A relative time after the current system time, consisting of a plus sign followed by an interval in the format described in the TIME FORMATS section of
sshd_config(5). - A raw seconds since epoch (Jan 1 1970 00:00:00 UTC) as a hexadecimal number beginning with
0x.
For example, feast your eyes ๐:
+52w1d Valid from now to 52 weeks and one day from now.
-4w:+4w
Valid from four weeks ago to four weeks from now.
20100101123000:20110101123000
Valid from 12:30 PM, January 1st, 2010 to 12:30 PM,
January 1st, 2011.
20100101123000Z:20110101123000Z
Similar, but interpreted in the UTC time zone rather
than the system time zone.
-1d:20110101
Valid from yesterday to midnight, January 1st, 2011.
0x1:0x2000000000
Valid from roughly early 1970 to May 2033.
-1m:forever
Valid from one minute ago and never expiring.
-vโ verbose mode ๐ Makesssh-keygenprint debugging messages about its progress. This is helpful for debugging moduli generation, fr fr. Multiple-voptions increase the verbosity. The maximum is 3. Don't try to go past 3, bestie, there's nothing there ๐-w providerโ specifies a path to a library that will be used when creating FIDO authenticator-hosted keys, overriding the default of using the internal USB HID support. ๐ Custom provider, fancy.-Y find-principalsโ find the principal(s) associated with the public key of a signature ๐ต๏ธ You provide the signature using the-sflag, and an authorized signers file using the-fflag. The format of the allowed signers file is documented in the โALLOWED SIGNERSโ section below. If one or more matching principals are found, they get returned on standard output. Found them, they were right there ๐-Y match-principalsโ find the principal matching the principal name provided using the-Iflag, inside the authorized signers file specified using the-fflag. If one or more matching principals are found, they get returned on standard output. Same energy, different search โจ-Y check-novalidateโ checks that a signature generated usingssh-keygen -Y signhas a valid structure. โ ๏ธ Heads up though: this does not validate whether a signature comes from an authorized signer. It's checking the shape, not the source, bestie. When testing a signature,ssh-keygenaccepts a message on standard input and a signature namespace using-n. A file containing the corresponding signature must also be supplied using the-sflag. Successful testing of the signature is signalled byssh-keygenreturning a zero exit status. โ-Y signโ the signing era โ๏ธโจ. This is wheressh-keygencryptographically signs a file or some data using an SSH key.
When it's in signing mode, ssh-keygen takes zero or more files to sign right there on the command-line โ and if you pass it no files at all, then ssh-keygen will sign data presented on standard input. Fr fr, it just handles it.
Signatures get written to the path of the input file with .sig appended onto the end, or to standard output if the message to be signed was read from standard input.
The key used for signing is specified using the -f option, and it may refer to either a private key, or a public key with the private half available via ssh-agent(1). You also must provide an additional signature namespace via the -n flag โ that's the whole thing that prevents signature confusion across different domains of use (e.g. file signing vs email signing, two completely different lanes ๐ฃ๏ธ). Namespaces are arbitrary strings, and may include: "file" for file signing, "email" for email signing. For custom uses, it is recommended to use names following a NAMESPACE@YOUR.DOMAIN pattern to generate unambiguous namespaces. ๐
-Y verifyโ the receipts-checking mode ๐. Request to verify a signature generated usingssh-keygen -Y signas described above.
When verifying a signature, ssh-keygen accepts a message on standard input and a signature namespace using -n. A file containing the corresponding signature must also be supplied using the -s flag, along with the identity of the signer using -I and a list of allowed signers via the -f flag. The format of the allowed signers file is documented in the โALLOWED SIGNERSโ section below. A file containing revoked keys can be passed using the -r flag. The revocation file may be a KRL or a one-per-line list of public keys. Successful verification by an authorized signer is signalled by ssh-keygen returning a zero exit status. โ
(zero exit status = the vibe check passed, bestie.)
-yโ this option will read a private OpenSSH format file and print an OpenSSH public key to stdout. Sneaky lil "show me the public half" button ๐-Zcipher โ specifies the cipher to use for encryption when writing an OpenSSH-format private key file. You can get the list of available ciphers using"ssh -Q cipher". The default is"aes256-ctr". ๐-zserial_number โ specifies a serial number to be embedded in the certificate so it can be distinguished from others from the same CA. If the serial_number is prefixed with a+character, then the serial number will be incremented for each certificate signed on a single command-line. The default serial number is zero. ๐ข
When generating a KRL, the -z flag is used to specify a KRL version number.
๐ MODULI GENERATION ๐
ssh-keygen may be used to generate groups for the Diffie-Hellman Group Exchange (DH-GEX) protocol. Generating these groups is a two-step process, and honestly it's giving two-part season finale: first, candidate primes are generated using a fast, but memory intensive process. Those candidate primes then get tested for suitability (a CPU-intensive process). Fast-then-thorough, we love a pipeline ๐
Generation of primes is performed using the -M generate option. The desired length of the primes may be specified by the -O bits option. For example:
# ssh-keygen -M generate -O bits=2048 moduli-2048.candidates
By default, the search for primes begins at a random point in the desired length range. This may be overridden using the -O start option, which specifies a different start point (in hex). ๐ฒ
Once a set of candidates have been generated, they must be screened for suitability. This may be performed using the -M screen option. In this mode ssh-keygen will read candidates from standard input (or a file specified using the -f option). For example:
# ssh-keygen -M screen -f moduli-2048.candidates moduli-2048
By default, each candidate will be subjected to 100 primality tests. This may be overridden using the -O prime-tests option. The DH generator value will be chosen automatically for the prime under consideration. If a specific generator is desired, it may be requested using the -O generator option. Valid generator values are 2, 3, and 5. โญ
Screened DH groups may be installed in /etc/ssh/moduli. It is important that this file contains moduli of a range of bit lengths. ๐ซถ
A number of options are available for moduli generation and screening via the -O flag:
lines=numberโ exit after screening the specified number of lines while performing DH candidate screening.start-line=line-numberโ start screening at the specified line number while performing DH candidate screening.checkpoint=filenameโ write the last line processed to the specified file while performing DH candidate screening. This will be used to skip lines in the input file that have already been processed if the job is restarted. (Basically a save point ๐พ iconic behaviour.)start=hex-valueโ specify start point (in hex) when generating candidate moduli for DH-GEX.generator=valueโ specify desired generator (in decimal) when testing candidate moduli for DH-GEX.
๐ CERTIFICATES ๐
okay so this is the part where ssh-keygen becomes a โจliteralโจ kingmaker, because it can sign keys to produce certificates that get used for user or host authentication. think of it like: instead of trusting a million rando keys, you trust one CA and that's it. main character energy fr.
so a certificate is made of:
- a public key ๐๏ธ
- some identity information
- zero or more principal (user or host) names
- a set of options
โฆand all of that is signed by a Certification Authority (CA) key. that's the whole point: clients or servers can then trust only the CA key and just verify its signature on a certificate, rather than having to trust a whole crowd of user/host keys. so much less chaotic bestie.
heads up!! OpenSSH certificates are a different, and much simpler, format to the X.509 certificates used in ssl(8). not the same thing, don't mix them up ๐ซถ
the two flavours ๐
ssh-keygen supports two types of certificates: user and host.
- user certificates authenticate users to servers
- host certificates authenticate server hosts to users
to generate a user certificate:
$ ssh-keygen -s /path/to/ca_key -I id -n user \
/path/to/user_key.pub
the resultant certificate will be placed in /path/to/user_key-cert.pub. iconic placement, no notes ๐
- the argument to
-Iis a key identifier that will be used in logs and may be used to revoke keys - the argument to
-nis one or more (comma-separated) principals, typically usernames, that the certificate represents
a host certificate requires the -h option:
$ ssh-keygen -s /path/to/ca_key -I id -h -n foo.example.org \
/path/to/host_key.pub
for host certificates, the principals specified using the -n argument are hostnames and may contain wildcard characters โจ
the host certificate will be output to /path/to/host_key-cert.pub.
CA key living somewhere fancy ๐
it is possible to sign using a CA key stored in a PKCS#11 token by providing the token library using -D and identifying the CA key by providing its public half as an argument to -s:
$ ssh-keygen -s ca_key.pub -D libpkcs11.so -I id -n user \
user_key.pub
similarly, it is possible for the CA key to be hosted in an ssh-agent(1). this is indicated by the -U flag and, again, the CA key must be identified by its public half.
$ ssh-keygen -Us ca_key.pub -I id -n user user_key.pub
in all cases, key_id is a "key identifier" that is logged by the server when the certificate is used for authentication. so it's literally your name in the group chat of the server logs ๐
limiting who's allowed ๐
certificates are limited to be valid for a set of principal (user/host) names. to generate a certificate for a specified set of principals:
$ ssh-keygen -s ca_key -I id -n user1,user2 user_key.pub
$ ssh-keygen -s ca_key -I id -h -n host.domain host_key.pub
additional limitations on the validity and use of user certificates may be specified through certificate options. a certificate option may:
- disable features of the SSH session
- be valid only when presented from particular source addresses
- force the use of a specific command
the options that are valid for user certificates ๐
clearโ clear all enabled permissions. this is useful for clearing the default set of permissions so permissions may be added individually. starting from a blank slate, bestie ๐งผcritical:name[=contents],extension:name[=contents]โ includes an arbitrary certificate critical option or extension. the specified name should include a domain suffix, e.g."name@example.com". if contents is specified then it is included as the contents of the extension/option encoded as a string, otherwise the extension/option is created with no contents (usually indicating a flag). extensions may be ignored by a client or server that does not recognise them, whereas unknown critical options will cause the certificate to be refused. so likeโฆ critical means critical fr fr ๐force-command=commandโ forces the execution of command instead of any shell or command specified by the user when the certificate is used for authentication. no free will, only vibes ๐no-agent-forwardingโ disablessh-agent(1)forwarding (permitted by default)no-port-forwardingโ disable port forwarding (permitted by default)no-ptyโ disable PTY allocation (permitted by default)no-user-rcโ disable execution of~/.ssh/rcbysshd(8)(permitted by default)no-x11-forwardingโ disable X11 forwarding (permitted by default)permit-agent-forwardingโ allowsssh-agent(1)forwardingpermit-port-forwardingโ allows port forwardingpermit-ptyโ allows PTY allocationpermit-user-rcโ allows execution of~/.ssh/rcbysshd(8)permit-X11-forwardingโ allows X11 forwardingno-touch-requiredโ do not require signatures made using this key include demonstration of user presence (e.g. by having the user touch the authenticator). this option only makes sense for the FIDO authenticator algorithmsecdsa-skanded25519-sksource-address=address_listโ restrict the source addresses from which the certificate is considered valid. the address_list is a comma-separated list of one or more address/netmask pairs in CIDR formatverify-requiredโ require signatures made using this key indicate that the user was first verified, e.g. by PIN or on-token biometrics. this option only makes sense for the FIDO authenticator algorithmsecdsa-skanded25519-sk
at present, no standard options are valid for host keys. rip host keys, nothing for you ๐ฅฒ
โฐ validity lifetime
finally, certificates may be defined with a validity lifetime. the -V option allows specification of certificate start and end times. a certificate that is presented at a time outside this range will not be considered valid. by default, certificates are valid from the Unix Epoch to the distant future โ so like, always and forever, lowkey romantic ๐ซถ
for certificates to be used for user or host authentication, the CA public key must be trusted by sshd(8) or ssh(1). refer to those manual pages for details โจ
๐ฆ FIDO AUTHENTICATOR ๐ฆ
ssh-keygen is able to generate FIDO authenticator-backed keys, after which they may be used much like any other key type supported by OpenSSH, so long as the hardware authenticator is attached when the keys are used ๐
FIDO authenticators generally require the user to explicitly authorise operations by touching or tapping them. yes bestie, physical contact, we love a tactile moment.
FIDO keys consist of two parts:
- a key handle part stored in the private key file on disk
- a per-device private key that is unique to each FIDO authenticator and that cannot be exported from the authenticator hardware
these are combined by the hardware at authentication time to derive the real key that is used to sign authentication challenges. it's giving teamwork honestly ๐ค
supported key types are ecdsa-sk and ed25519-sk.
the options that are valid for FIDO keys ๐
applicationโ override the default FIDO application/origin string of"ssh:". this may be useful when generating host or domain-specific resident keys. the specified application string must begin with"ssh:"challenge=pathโ specifies a path to a challenge string that will be passed to the FIDO authenticator during key generation. the challenge string may be used as part of an out-of-band protocol for key enrollment (a random challenge is used by default)deviceโ explicitly specify afido(4)device to use, rather than letting the authenticator middleware select oneno-touch-requiredโ indicate that the generated private key should not require touch events (user presence) when making signatures. note thatsshd(8)will refuse such signatures by default, unless overridden via anauthorized_keysoptionresidentโ indicate that the key handle should be stored on the FIDO authenticator itself. this makes it easier to use the authenticator on multiple computers. resident keys may be supported on FIDO2 authenticators and typically require that a PIN be set on the authenticator prior to generation. resident keys may be loaded off the authenticator usingssh-add(1). storing both parts of a key on a FIDO authenticator increases the likelihood of an attacker being able to use a stolen authenticator device โ ๏ธuserโ a username to be associated with a resident key, overriding the empty default username. specifying a username may be useful when generating multiple resident keys for the same application nameverify-requiredโ indicate that this private key should require user verification for each signature. not all FIDO authenticators support this option. currently PIN authentication is the only supported verification method, but other methods may be supported in the futurewrite-attestation=pathโ may be used at key generation time to record the attestation data returned from FIDO authenticators during key generation. this information is potentially sensitive. by default, this information is discarded ๐
๐ KEY REVOCATION LISTS ๐
okay so bestie, ssh-keygen can also run the OpenSSH format Key Revocation Lists, aka KRLs. these are binary files that list exactly which keys or certs are โจcancelledโจ, and they're stupidly compact โ we're talking as little as one bit per certificate if you're revoking them by serial number. one bit. iconic efficiency tbh.
you make KRLs with the -k flag. it reads one or more files off the command line and builds you a brand new KRL. those files can hold either a KRL specification (more on that below) or plain public keys, one per line. plain public keys get revoked by sticking their hash or contents in the KRL, and certificates get revoked by serial number or key ID (if the serial is zero or not available).
using a KRL specification gives you explicit control over which record types get used to revoke stuff, and it means you can directly revoke certificates by serial number or key ID without having the whole original certificate on hand. so convenient. so slay.
a KRL specification is just lines, each one holding one of these directives, followed by a colon and some directive-specific info:
serial: serial_number[-serial_number]โ revokes a certificate with the specified serial number. serial numbers are 64-bit values, not including zero, and they can be written in decimal, hex or octal. if you give two serial numbers separated by a hyphen, then the whole range of serial numbers including and between each is revoked. the CA key must have been specified on thessh-keygencommand line using the-soption.id: key_idโ revokes a certificate with the specified key ID string. same deal, the CA key must have been specified on thessh-keygencommand line using the-soption.key: public_keyโ revokes the specified key. if a certificate is listed, then it gets revoked as a plain public key.sha1: public_keyโ revokes the specified key by including its SHA1 hash in the KRL.sha256: public_keyโ revokes the specified key by including its SHA256 hash in the KRL. heads up: KRLs that revoke keys by SHA256 hash are not supported by OpenSSH versions prior to 7.9.hash: fingerprintโ revokes a key using a fingerprint hash, like the one you'd grab from ansshd(8)authentication log message or from thessh-keygen -lflag. only SHA256 fingerprints are supported here, and the resulting KRLs are not supported by OpenSSH versions prior to 7.9.
you can also update KRLs by using the -u flag alongside -k. when you do that, the keys listed on the command line get merged into the KRL, added on top of whatever's already in there. ๐ซถ
and yes, you can absolutely query a KRL to test whether it revokes a particular key (or keys). the -Q flag queries an existing KRL and tests every key you list on the command line. if any key you listed has been revoked (or an error got hit), then ssh-keygen exits with a non-zero exit status. a zero exit status is only returned if no key was revoked. no cap.
๐ ALLOWED SIGNERS ๐
when it's verifying signatures, ssh-keygen uses a lil simple list of identities and keys to figure out whether a signature comes from an authorized source. this "allowed signers" file uses a format patterned after the AUTHORIZED_KEYS FILE FORMAT described in sshd(8). every line has these space-separated fields: principals, options, keytype, base64-encoded key. empty lines and lines starting with a โ#โ get ignored as comments. ๐
the principals field is a pattern-list (see PATTERNS in ssh_config(5)) made of one or more comma-separated USER@DOMAIN identity patterns that are accepted for signing. when verifying, the identity you present via the -I option must match a principals pattern for that key to even be considered acceptable for verification.
the options (if they're there) are comma-separated option specifications. no spaces allowed, except inside double quotes. here's what's supported (and btw, option keywords are case-insensitive):
cert-authorityโ says this key is accepted as a certificate authority (CA) and that certificates signed by this CA may be accepted for verification.namespaces=namespace-listโ specifies a pattern-list of namespaces accepted for this key. if this option is present, the signature namespace embedded in the signature object and presented on the verification command-line must match the specified list before the key will be considered acceptable.valid-after=timestampโ says the key is valid for use at or after the specified timestamp, which can be a date or time in theYYYYMMDD[Z]orYYYYMMDDHHMM[SS][Z]formats. dates and times get interpreted in the current system time zone unless you slap aZcharacter on the end, which makes them interpreted in the UTC time zone.valid-before=timestampโ says the key is valid for use at or before the specified timestamp.
when verifying signatures made by certificates, the expected principal name has to match both the principals pattern in the allowed signers file and the principals embedded in the certificate itself. double check, bestie.
here's an example allowed signers file, look at her:
# Comments allowed at start of line
user1@example.com,user2@example.com ssh-rsa AAAAX1...
# A certificate authority, trusted for all principals in a domain.
*@example.com cert-authority ssh-ed25519 AAAB4...
# A key that is accepted only for file signing.
user2@example.com namespaces="file" ssh-ed25519 AAA41...
๐ ENVIRONMENT ๐
SSH_SK_PROVIDERโ specifies a path to a library that'll be used when loading any FIDO authenticator-hosted keys, overriding the default of using the built-in USB HID support.
๐ FILES ๐
~/.ssh/id_ecdsa~/.ssh/id_ecdsa_sk~/.ssh/id_ed25519~/.ssh/id_ed25519_sk~/.ssh/id_mldsa44_ed25519~/.ssh/id_rsa
contains the ECDSA, authenticator-hosted ECDSA, Ed25519, authenticator-hosted Ed25519 or RSA authentication identity of the user. this file should not be readable by anyone but the user. you can specify a passphrase when generating the key, and that passphrase gets used to encrypt the private part of this file using 128-bit AES. this file is not automatically accessed by ssh-keygen, but it's offered as the default file for the private key. ssh(1) will read this file when a login attempt is made.
~/.ssh/id_ecdsa.pub~/.ssh/id_ecdsa_sk.pub~/.ssh/id_ed25519.pub~/.ssh/id_ed25519_sk.pub~/.ssh/id_mldsa44_ed25519.pub~/.ssh/id_rsa.pub
contains the ECDSA, authenticator-hosted ECDSA, Ed25519, authenticator-hosted Ed25519 or RSA public key for authentication. the contents of this file should be added to ~/.ssh/authorized_keys on all machines where the user wishes to log in using public key authentication. there is no need to keep the contents of this file secret. it's public, she's out and proud ๐
/etc/ssh/moduli
contains Diffie-Hellman groups used for DH-GEX. the file format is described in moduli(5).
๐ SEE ALSO ๐
ssh(1), ssh-add(1), ssh-agent(1), moduli(5), sshd(8)
The Secure Shell (SSH) Public Key File Format, RFC 4716, 2006.
๐ AUTHORS ๐
OpenSSH is a derivative of the original and free ssh 1.2.12 release by Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo de Raadt and Dug Song removed many bugs, re-added newer features and created OpenSSH. Markus Friedl contributed the support for SSH protocol versions 1.5 and 2.0.
and that's the whole page bestie, we did it ๐ this one's from the Debian folks, dated October 1, 2026, and it lives under the name SSH-KEYGEN(1). go forth and revoke responsibly ๐ โจ
๐ฆ where this page comes from
- arch rolling: openssh 10.6p1-1
- arch rolling: openssh 10.6p1-2 ยท 0BSD AND BSD-2-Clause AND BSD-3-Clause AND ISC AND LicenseRef-Public-Domain AND MIT
- nixos 26.05: openssh 10.6p1
- nixos 26.05: openssh-test 10.6p1
- nixpkgs unstable: openssh 10.6p1
- nixpkgs unstable: openssh-test 10.6p1
- Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
- Copyright (c) 1999,2000 Markus Friedl. All rights reserved
- Copyright (c) 1999 Aaron Campbell. All rights reserved
- Copyright (c) 1999 Theo de Raadt. All rights reserved
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms