xref: /openbsd-src/usr.bin/ssh/ssh-keygen.1 (revision 18270f79f17989f9cfedd96c0d9a34fd91cdb415)
1.\"	$OpenBSD: ssh-keygen.1,v 1.215 2021/07/23 06:01:17 jmc Exp $
2.\"
3.\" Author: Tatu Ylonen <ylo@cs.hut.fi>
4.\" Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5.\"                    All rights reserved
6.\"
7.\" As far as I am concerned, the code I have written for this software
8.\" can be used freely for any purpose.  Any derived versions of this
9.\" software must be clearly marked as such, and if the derived work is
10.\" incompatible with the protocol description in the RFC file, it must be
11.\" called by a name other than "ssh" or "Secure Shell".
12.\"
13.\"
14.\" Copyright (c) 1999,2000 Markus Friedl.  All rights reserved.
15.\" Copyright (c) 1999 Aaron Campbell.  All rights reserved.
16.\" Copyright (c) 1999 Theo de Raadt.  All rights reserved.
17.\"
18.\" Redistribution and use in source and binary forms, with or without
19.\" modification, are permitted provided that the following conditions
20.\" are met:
21.\" 1. Redistributions of source code must retain the above copyright
22.\"    notice, this list of conditions and the following disclaimer.
23.\" 2. Redistributions in binary form must reproduce the above copyright
24.\"    notice, this list of conditions and the following disclaimer in the
25.\"    documentation and/or other materials provided with the distribution.
26.\"
27.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37.\"
38.Dd $Mdocdate: July 23 2021 $
39.Dt SSH-KEYGEN 1
40.Os
41.Sh NAME
42.Nm ssh-keygen
43.Nd OpenSSH authentication key utility
44.Sh SYNOPSIS
45.Nm ssh-keygen
46.Op Fl q
47.Op Fl a Ar rounds
48.Op Fl b Ar bits
49.Op Fl C Ar comment
50.Op Fl f Ar output_keyfile
51.Op Fl m Ar format
52.Op Fl N Ar new_passphrase
53.Op Fl O Ar option
54.Op Fl t Cm dsa | ecdsa | ecdsa-sk | ed25519 | ed25519-sk | rsa
55.Op Fl w Ar provider
56.Op Fl Z Ar cipher
57.Nm ssh-keygen
58.Fl p
59.Op Fl a Ar rounds
60.Op Fl f Ar keyfile
61.Op Fl m Ar format
62.Op Fl N Ar new_passphrase
63.Op Fl P Ar old_passphrase
64.Op Fl Z Ar cipher
65.Nm ssh-keygen
66.Fl i
67.Op Fl f Ar input_keyfile
68.Op Fl m Ar key_format
69.Nm ssh-keygen
70.Fl e
71.Op Fl f Ar input_keyfile
72.Op Fl m Ar key_format
73.Nm ssh-keygen
74.Fl y
75.Op Fl f Ar input_keyfile
76.Nm ssh-keygen
77.Fl c
78.Op Fl a Ar rounds
79.Op Fl C Ar comment
80.Op Fl f Ar keyfile
81.Op Fl P Ar passphrase
82.Nm ssh-keygen
83.Fl l
84.Op Fl v
85.Op Fl E Ar fingerprint_hash
86.Op Fl f Ar input_keyfile
87.Nm ssh-keygen
88.Fl B
89.Op Fl f Ar input_keyfile
90.Nm ssh-keygen
91.Fl D Ar pkcs11
92.Nm ssh-keygen
93.Fl F Ar hostname
94.Op Fl lv
95.Op Fl f Ar known_hosts_file
96.Nm ssh-keygen
97.Fl H
98.Op Fl f Ar known_hosts_file
99.Nm ssh-keygen
100.Fl K
101.Op Fl a Ar rounds
102.Op Fl w Ar provider
103.Nm ssh-keygen
104.Fl R Ar hostname
105.Op Fl f Ar known_hosts_file
106.Nm ssh-keygen
107.Fl r Ar hostname
108.Op Fl g
109.Op Fl f Ar input_keyfile
110.Nm ssh-keygen
111.Fl M Cm generate
112.Op Fl O Ar option
113.Ar output_file
114.Nm ssh-keygen
115.Fl M Cm screen
116.Op Fl f Ar input_file
117.Op Fl O Ar option
118.Ar output_file
119.Nm ssh-keygen
120.Fl I Ar certificate_identity
121.Fl s Ar ca_key
122.Op Fl hU
123.Op Fl D Ar pkcs11_provider
124.Op Fl n Ar principals
125.Op Fl O Ar option
126.Op Fl V Ar validity_interval
127.Op Fl z Ar serial_number
128.Ar
129.Nm ssh-keygen
130.Fl L
131.Op Fl f Ar input_keyfile
132.Nm ssh-keygen
133.Fl A
134.Op Fl a Ar rounds
135.Op Fl f Ar prefix_path
136.Nm ssh-keygen
137.Fl k
138.Fl f Ar krl_file
139.Op Fl u
140.Op Fl s Ar ca_public
141.Op Fl z Ar version_number
142.Ar
143.Nm ssh-keygen
144.Fl Q
145.Op Fl l
146.Fl f Ar krl_file
147.Ar
148.Nm ssh-keygen
149.Fl Y Cm find-principals
150.Op Fl O Ar option
151.Fl s Ar signature_file
152.Fl f Ar allowed_signers_file
153.Nm ssh-keygen
154.Fl Y Cm check-novalidate
155.Op Fl O Ar option
156.Fl n Ar namespace
157.Fl s Ar signature_file
158.Nm ssh-keygen
159.Fl Y Cm sign
160.Fl f Ar key_file
161.Fl n Ar namespace
162.Ar
163.Nm ssh-keygen
164.Fl Y Cm verify
165.Op Fl O Ar option
166.Fl f Ar allowed_signers_file
167.Fl I Ar signer_identity
168.Fl n Ar namespace
169.Fl s Ar signature_file
170.Op Fl r Ar revocation_file
171.Sh DESCRIPTION
172.Nm
173generates, manages and converts authentication keys for
174.Xr ssh 1 .
175.Nm
176can create keys for use by SSH protocol version 2.
177.Pp
178The type of key to be generated is specified with the
179.Fl t
180option.
181If invoked without any arguments,
182.Nm
183will generate an RSA key.
184.Pp
185.Nm
186is also used to generate groups for use in Diffie-Hellman group
187exchange (DH-GEX).
188See the
189.Sx MODULI GENERATION
190section for details.
191.Pp
192Finally,
193.Nm
194can be used to generate and update Key Revocation Lists, and to test whether
195given keys have been revoked by one.
196See the
197.Sx KEY REVOCATION LISTS
198section for details.
199.Pp
200Normally each user wishing to use SSH
201with public key authentication runs this once to create the authentication
202key in
203.Pa ~/.ssh/id_dsa ,
204.Pa ~/.ssh/id_ecdsa ,
205.Pa ~/.ssh/id_ecdsa_sk ,
206.Pa ~/.ssh/id_ed25519 ,
207.Pa ~/.ssh/id_ed25519_sk
208or
209.Pa ~/.ssh/id_rsa .
210Additionally, the system administrator may use this to generate host keys,
211as seen in
212.Pa /etc/rc .
213.Pp
214Normally this program generates the key and asks for a file in which
215to store the private key.
216The public key is stored in a file with the same name but
217.Dq .pub
218appended.
219The program also asks for a passphrase.
220The passphrase may be empty to indicate no passphrase
221(host keys must have an empty passphrase), or it may be a string of
222arbitrary length.
223A passphrase is similar to a password, except it can be a phrase with a
224series of words, punctuation, numbers, whitespace, or any string of
225characters you want.
226Good passphrases are 10-30 characters long, are
227not simple sentences or otherwise easily guessable (English
228prose has only 1-2 bits of entropy per character, and provides very bad
229passphrases), and contain a mix of upper and lowercase letters,
230numbers, and non-alphanumeric characters.
231The passphrase can be changed later by using the
232.Fl p
233option.
234.Pp
235There is no way to recover a lost passphrase.
236If the passphrase is lost or forgotten, a new key must be generated
237and the corresponding public key copied to other machines.
238.Pp
239.Nm
240will by default write keys in an OpenSSH-specific format.
241This format is preferred as it offers better protection for
242keys at rest as well as allowing storage of key comments within
243the private key file itself.
244The key comment may be useful to help identify the key.
245The comment is initialized to
246.Dq user@host
247when the key is created, but can be changed using the
248.Fl c
249option.
250.Pp
251It is still possible for
252.Nm
253to write the previously-used PEM format private keys using the
254.Fl m
255flag.
256This may be used when generating new keys, and existing new-format
257keys may be converted using this option in conjunction with the
258.Fl p
259(change passphrase) flag.
260.Pp
261After a key is generated,
262.Nm
263will ask where the keys
264should be placed to be activated.
265.Pp
266The options are as follows:
267.Bl -tag -width Ds
268.It Fl A
269For each of the key types (rsa, dsa, ecdsa and ed25519)
270for which host keys
271do not exist, generate the host keys with the default key file path,
272an empty passphrase, default bits for the key type, and default comment.
273If
274.Fl f
275has also been specified, its argument is used as a prefix to the
276default path for the resulting host key files.
277This is used by
278.Pa /etc/rc
279to generate new host keys.
280.It Fl a Ar rounds
281When saving a private key, this option specifies the number of KDF
282(key derivation function, currently
283.Xr bcrypt_pbkdf 3 )
284rounds used.
285Higher numbers result in slower passphrase verification and increased
286resistance to brute-force password cracking (should the keys be stolen).
287The default is 16 rounds.
288.It Fl B
289Show the bubblebabble digest of specified private or public key file.
290.It Fl b Ar bits
291Specifies the number of bits in the key to create.
292For RSA keys, the minimum size is 1024 bits and the default is 3072 bits.
293Generally, 3072 bits is considered sufficient.
294DSA keys must be exactly 1024 bits as specified by FIPS 186-2.
295For ECDSA keys, the
296.Fl b
297flag determines the key length by selecting from one of three elliptic
298curve sizes: 256, 384 or 521 bits.
299Attempting to use bit lengths other than these three values for ECDSA keys
300will fail.
301ECDSA-SK, Ed25519 and Ed25519-SK keys have a fixed length and the
302.Fl b
303flag will be ignored.
304.It Fl C Ar comment
305Provides a new comment.
306.It Fl c
307Requests changing the comment in the private and public key files.
308The program will prompt for the file containing the private keys, for
309the passphrase if the key has one, and for the new comment.
310.It Fl D Ar pkcs11
311Download the public keys provided by the PKCS#11 shared library
312.Ar pkcs11 .
313When used in combination with
314.Fl s ,
315this option indicates that a CA key resides in a PKCS#11 token (see the
316.Sx CERTIFICATES
317section for details).
318.It Fl E Ar fingerprint_hash
319Specifies the hash algorithm used when displaying key fingerprints.
320Valid options are:
321.Dq md5
322and
323.Dq sha256 .
324The default is
325.Dq sha256 .
326.It Fl e
327This option will read a private or public OpenSSH key file and
328print to stdout a public key in one of the formats specified by the
329.Fl m
330option.
331The default export format is
332.Dq RFC4716 .
333This option allows exporting OpenSSH keys for use by other programs, including
334several commercial SSH implementations.
335.It Fl F Ar hostname | [hostname]:port
336Search for the specified
337.Ar hostname
338(with optional port number)
339in a
340.Pa known_hosts
341file, listing any occurrences found.
342This option is useful to find hashed host names or addresses and may also be
343used in conjunction with the
344.Fl H
345option to print found keys in a hashed format.
346.It Fl f Ar filename
347Specifies the filename of the key file.
348.It Fl g
349Use generic DNS format when printing fingerprint resource records using the
350.Fl r
351command.
352.It Fl H
353Hash a
354.Pa known_hosts
355file.
356This replaces all hostnames and addresses with hashed representations
357within the specified file; the original content is moved to a file with
358a .old suffix.
359These hashes may be used normally by
360.Nm ssh
361and
362.Nm sshd ,
363but they do not reveal identifying information should the file's contents
364be disclosed.
365This option will not modify existing hashed hostnames and is therefore safe
366to use on files that mix hashed and non-hashed names.
367.It Fl h
368When signing a key, create a host certificate instead of a user
369certificate.
370Please see the
371.Sx CERTIFICATES
372section for details.
373.It Fl I Ar certificate_identity
374Specify the key identity when signing a public key.
375Please see the
376.Sx CERTIFICATES
377section for details.
378.It Fl i
379This option will read an unencrypted private (or public) key file
380in the format specified by the
381.Fl m
382option and print an OpenSSH compatible private
383(or public) key to stdout.
384This option allows importing keys from other software, including several
385commercial SSH implementations.
386The default import format is
387.Dq RFC4716 .
388.It Fl K
389Download resident keys from a FIDO authenticator.
390Public and private key files will be written to the current directory for
391each downloaded key.
392If multiple FIDO authenticators are attached, keys will be downloaded from
393the first touched authenticator.
394.It Fl k
395Generate a KRL file.
396In this mode,
397.Nm
398will generate a KRL file at the location specified via the
399.Fl f
400flag that revokes every key or certificate presented on the command line.
401Keys/certificates to be revoked may be specified by public key file or
402using the format described in the
403.Sx KEY REVOCATION LISTS
404section.
405.It Fl L
406Prints the contents of one or more certificates.
407.It Fl l
408Show fingerprint of specified public key file.
409For RSA and DSA keys
410.Nm
411tries to find the matching public key file and prints its fingerprint.
412If combined with
413.Fl v ,
414a visual ASCII art representation of the key is supplied with the
415fingerprint.
416.It Fl M Cm generate
417Generate candidate Diffie-Hellman Group Exchange (DH-GEX) parameters for
418eventual use by the
419.Sq diffie-hellman-group-exchange-*
420key exchange methods.
421The numbers generated by this operation must be further screened before
422use.
423See the
424.Sx MODULI GENERATION
425section for more information.
426.It Fl M Cm screen
427Screen candidate parameters for Diffie-Hellman Group Exchange.
428This will accept a list of candidate numbers and test that they are
429safe (Sophie Germain) primes with acceptable group generators.
430The results of this operation may be added to the
431.Pa /etc/moduli
432file.
433See the
434.Sx MODULI GENERATION
435section for more information.
436.It Fl m Ar key_format
437Specify a key format for key generation, the
438.Fl i
439(import),
440.Fl e
441(export) conversion options, and the
442.Fl p
443change passphrase operation.
444The latter may be used to convert between OpenSSH private key and PEM
445private key formats.
446The supported key formats are:
447.Dq RFC4716
448(RFC 4716/SSH2 public or private key),
449.Dq PKCS8
450(PKCS8 public or private key)
451or
452.Dq PEM
453(PEM public key).
454By default OpenSSH will write newly-generated private keys in its own
455format, but when converting public keys for export the default format is
456.Dq RFC4716 .
457Setting a format of
458.Dq PEM
459when generating or updating a supported private key type will cause the
460key to be stored in the legacy PEM private key format.
461.It Fl N Ar new_passphrase
462Provides the new passphrase.
463.It Fl n Ar principals
464Specify one or more principals (user or host names) to be included in
465a certificate when signing a key.
466Multiple principals may be specified, separated by commas.
467Please see the
468.Sx CERTIFICATES
469section for details.
470.It Fl O Ar option
471Specify a key/value option.
472These are specific to the operation that
473.Nm
474has been requested to perform.
475.Pp
476When signing certificates, one of the options listed in the
477.Sx CERTIFICATES
478section may be specified here.
479.Pp
480When performing moduli generation or screening, one of the options
481listed in the
482.Sx MODULI GENERATION
483section may be specified.
484.Pp
485When generating a key that will be hosted on a FIDO authenticator,
486this flag may be used to specify key-specific options.
487Those supported at present are:
488.Bl -tag -width Ds
489.It Cm application
490Override the default FIDO application/origin string of
491.Dq ssh: .
492This may be useful when generating host or domain-specific resident keys.
493The specified application string must begin with
494.Dq ssh: .
495.It Cm challenge Ns = Ns Ar path
496Specifies a path to a challenge string that will be passed to the
497FIDO token during key generation.
498The challenge string may be used as part of an out-of-band
499protocol for key enrollment
500(a random challenge is used by default).
501.It Cm device
502Explicitly specify a
503.Xr fido 4
504device to use, rather than letting the token middleware select one.
505.It Cm no-touch-required
506Indicate that the generated private key should not require touch
507events (user presence) when making signatures.
508Note that
509.Xr sshd 8
510will refuse such signatures by default, unless overridden via
511an authorized_keys option.
512.It Cm resident
513Indicate that the key should be stored on the FIDO authenticator itself.
514Resident keys may be supported on FIDO2 tokens and typically require that
515a PIN be set on the token prior to generation.
516Resident keys may be loaded off the token using
517.Xr ssh-add 1 .
518.It Cm user
519A username to be associated with a resident key,
520overriding the empty default username.
521Specifying a username may be useful when generating multiple resident keys
522for the same application name.
523.It Cm verify-required
524Indicate that this private key should require user verification for
525each signature.
526Not all FIDO tokens support this option.
527Currently PIN authentication is the only supported verification method,
528but other methods may be supported in the future.
529.It Cm write-attestation Ns = Ns Ar path
530May be used at key generation time to record the attestation data
531returned from FIDO tokens during key generation.
532Please note that this information is potentially sensitive.
533By default, this information is discarded.
534.El
535.Pp
536When performing signature-related options using the
537.Fl Y
538flag, the following options are accepted:
539.Bl -tag -width Ds
540.It Cm verify-time Ns = Ns Ar timestamp
541Specifies a time to use when validating signatures instead of the current
542time.
543The time may be specified as a date in YYYYMMDD format or a time
544in YYYYMMDDHHMM[SS] format.
545.El
546.Pp
547The
548.Fl O
549option may be specified multiple times.
550.It Fl P Ar passphrase
551Provides the (old) passphrase.
552.It Fl p
553Requests changing the passphrase of a private key file instead of
554creating a new private key.
555The program will prompt for the file
556containing the private key, for the old passphrase, and twice for the
557new passphrase.
558.It Fl Q
559Test whether keys have been revoked in a KRL.
560If the
561.Fl l
562option is also specified then the contents of the KRL will be printed.
563.It Fl q
564Silence
565.Nm ssh-keygen .
566.It Fl R Ar hostname | [hostname]:port
567Removes all keys belonging to the specified
568.Ar hostname
569(with optional port number)
570from a
571.Pa known_hosts
572file.
573This option is useful to delete hashed hosts (see the
574.Fl H
575option above).
576.It Fl r Ar hostname
577Print the SSHFP fingerprint resource record named
578.Ar hostname
579for the specified public key file.
580.It Fl s Ar ca_key
581Certify (sign) a public key using the specified CA key.
582Please see the
583.Sx CERTIFICATES
584section for details.
585.Pp
586When generating a KRL,
587.Fl s
588specifies a path to a CA public key file used to revoke certificates directly
589by key ID or serial number.
590See the
591.Sx KEY REVOCATION LISTS
592section for details.
593.It Fl t Cm dsa | ecdsa | ecdsa-sk | ed25519 | ed25519-sk | rsa
594Specifies the type of key to create.
595The possible values are
596.Dq dsa ,
597.Dq ecdsa ,
598.Dq ecdsa-sk ,
599.Dq ed25519 ,
600.Dq ed25519-sk ,
601or
602.Dq rsa .
603.Pp
604This flag may also be used to specify the desired signature type when
605signing certificates using an RSA CA key.
606The available RSA signature variants are
607.Dq ssh-rsa
608(SHA1 signatures, not recommended),
609.Dq rsa-sha2-256 ,
610and
611.Dq rsa-sha2-512
612(the default).
613.It Fl U
614When used in combination with
615.Fl s ,
616this option indicates that a CA key resides in a
617.Xr ssh-agent 1 .
618See the
619.Sx CERTIFICATES
620section for more information.
621.It Fl u
622Update a KRL.
623When specified with
624.Fl k ,
625keys listed via the command line are added to the existing KRL rather than
626a new KRL being created.
627.It Fl V Ar validity_interval
628Specify a validity interval when signing a certificate.
629A validity interval may consist of a single time, indicating that the
630certificate is valid beginning now and expiring at that time, or may consist
631of two times separated by a colon to indicate an explicit time interval.
632.Pp
633The start time may be specified as the string
634.Dq always
635to indicate the certificate has no specified start time,
636a date in YYYYMMDD format, a time in YYYYMMDDHHMM[SS] format,
637a relative time (to the current time) consisting of a minus sign followed by
638an interval in the format described in the
639TIME FORMATS section of
640.Xr sshd_config 5 .
641.Pp
642The end time may be specified as a YYYYMMDD date, a YYYYMMDDHHMM[SS] time,
643a relative time starting with a plus character or the string
644.Dq forever
645to indicate that the certificate has no expiry date.
646.Pp
647For example:
648.Dq +52w1d
649(valid from now to 52 weeks and one day from now),
650.Dq -4w:+4w
651(valid from four weeks ago to four weeks from now),
652.Dq 20100101123000:20110101123000
653(valid from 12:30 PM, January 1st, 2010 to 12:30 PM, January 1st, 2011),
654.Dq -1d:20110101
655(valid from yesterday to midnight, January 1st, 2011),
656.Dq -1m:forever
657(valid from one minute ago and never expiring).
658.It Fl v
659Verbose mode.
660Causes
661.Nm
662to print debugging messages about its progress.
663This is helpful for debugging moduli generation.
664Multiple
665.Fl v
666options increase the verbosity.
667The maximum is 3.
668.It Fl w Ar provider
669Specifies a path to a library that will be used when creating
670FIDO authenticator-hosted keys, overriding the default of using
671the internal USB HID support.
672.It Fl Y Cm find-principals
673Find the principal(s) associated with the public key of a signature,
674provided using the
675.Fl s
676flag in an authorized signers file provided using the
677.Fl f
678flag.
679The format of the allowed signers file is documented in the
680.Sx ALLOWED SIGNERS
681section below.
682If one or more matching principals are found, they are returned on
683standard output.
684.It Fl Y Cm check-novalidate
685Checks that a signature generated using
686.Nm
687.Fl Y Cm sign
688has a valid structure.
689This does not validate if a signature comes from an authorized signer.
690When testing a signature,
691.Nm
692accepts a message on standard input and a signature namespace using
693.Fl n .
694A file containing the corresponding signature must also be supplied using the
695.Fl s
696flag.
697Successful testing of the signature is signalled by
698.Nm
699returning a zero exit status.
700.It Fl Y Cm sign
701Cryptographically sign a file or some data using a SSH key.
702When signing,
703.Nm
704accepts zero or more files to sign on the command-line - if no files
705are specified then
706.Nm
707will sign data presented on standard input.
708Signatures are written to the path of the input file with
709.Dq .sig
710appended, or to standard output if the message to be signed was read from
711standard input.
712.Pp
713The key used for signing is specified using the
714.Fl f
715option and may refer to either a private key, or a public key with the private
716half available via
717.Xr ssh-agent 1 .
718An additional signature namespace, used to prevent signature confusion across
719different domains of use (e.g. file signing vs email signing) must be provided
720via the
721.Fl n
722flag.
723Namespaces are arbitrary strings, and may include:
724.Dq file
725for file signing,
726.Dq email
727for email signing.
728For custom uses, it is recommended to use names following a
729NAMESPACE@YOUR.DOMAIN pattern to generate unambiguous namespaces.
730.It Fl Y Cm verify
731Request to verify a signature generated using
732.Nm
733.Fl Y Cm sign
734as described above.
735When verifying a signature,
736.Nm
737accepts a message on standard input and a signature namespace using
738.Fl n .
739A file containing the corresponding signature must also be supplied using the
740.Fl s
741flag, along with the identity of the signer using
742.Fl I
743and a list of allowed signers via the
744.Fl f
745flag.
746The format of the allowed signers file is documented in the
747.Sx ALLOWED SIGNERS
748section below.
749A file containing revoked keys can be passed using the
750.Fl r
751flag.
752The revocation file may be a KRL or a one-per-line list of public keys.
753Successful verification by an authorized signer is signalled by
754.Nm
755returning a zero exit status.
756.It Fl y
757This option will read a private
758OpenSSH format file and print an OpenSSH public key to stdout.
759.It Fl Z Ar cipher
760Specifies the cipher to use for encryption when writing an OpenSSH-format
761private key file.
762The list of available ciphers may be obtained using
763.Qq ssh -Q cipher .
764The default is
765.Dq aes256-ctr .
766.It Fl z Ar serial_number
767Specifies a serial number to be embedded in the certificate to distinguish
768this certificate from others from the same CA.
769If the
770.Ar serial_number
771is prefixed with a
772.Sq +
773character, then the serial number will be incremented for each certificate
774signed on a single command-line.
775The default serial number is zero.
776.Pp
777When generating a KRL, the
778.Fl z
779flag is used to specify a KRL version number.
780.El
781.Sh MODULI GENERATION
782.Nm
783may be used to generate groups for the Diffie-Hellman Group Exchange
784(DH-GEX) protocol.
785Generating these groups is a two-step process: first, candidate
786primes are generated using a fast, but memory intensive process.
787These candidate primes are then tested for suitability (a CPU-intensive
788process).
789.Pp
790Generation of primes is performed using the
791.Fl M Cm generate
792option.
793The desired length of the primes may be specified by the
794.Fl O Cm bits
795option.
796For example:
797.Pp
798.Dl # ssh-keygen -M generate -O bits=2048 moduli-2048.candidates
799.Pp
800By default, the search for primes begins at a random point in the
801desired length range.
802This may be overridden using the
803.Fl O Cm start
804option, which specifies a different start point (in hex).
805.Pp
806Once a set of candidates have been generated, they must be screened for
807suitability.
808This may be performed using the
809.Fl M Cm screen
810option.
811In this mode
812.Nm
813will read candidates from standard input (or a file specified using the
814.Fl f
815option).
816For example:
817.Pp
818.Dl # ssh-keygen -M screen -f moduli-2048.candidates moduli-2048
819.Pp
820By default, each candidate will be subjected to 100 primality tests.
821This may be overridden using the
822.Fl O Cm prime-tests
823option.
824The DH generator value will be chosen automatically for the
825prime under consideration.
826If a specific generator is desired, it may be requested using the
827.Fl O Cm generator
828option.
829Valid generator values are 2, 3, and 5.
830.Pp
831Screened DH groups may be installed in
832.Pa /etc/moduli .
833It is important that this file contains moduli of a range of bit lengths.
834.Pp
835A number of options are available for moduli generation and screening via the
836.Fl O
837flag:
838.Bl -tag -width Ds
839.It Ic lines Ns = Ns Ar number
840Exit after screening the specified number of lines while performing DH
841candidate screening.
842.It Ic start-line Ns = Ns Ar line-number
843Start screening at the specified line number while performing DH candidate
844screening.
845.It Ic checkpoint Ns = Ns Ar filename
846Write the last line processed to the specified file while performing DH
847candidate screening.
848This will be used to skip lines in the input file that have already been
849processed if the job is restarted.
850.It Ic memory Ns = Ns Ar mbytes
851Specify the amount of memory to use (in megabytes) when generating
852candidate moduli for DH-GEX.
853.It Ic start Ns = Ns Ar hex-value
854Specify start point (in hex) when generating candidate moduli for DH-GEX.
855.It Ic generator Ns = Ns Ar value
856Specify desired generator (in decimal) when testing candidate moduli for DH-GEX.
857.El
858.Sh CERTIFICATES
859.Nm
860supports signing of keys to produce certificates that may be used for
861user or host authentication.
862Certificates consist of a public key, some identity information, zero or
863more principal (user or host) names and a set of options that
864are signed by a Certification Authority (CA) key.
865Clients or servers may then trust only the CA key and verify its signature
866on a certificate rather than trusting many user/host keys.
867Note that OpenSSH certificates are a different, and much simpler, format to
868the X.509 certificates used in
869.Xr ssl 8 .
870.Pp
871.Nm
872supports two types of certificates: user and host.
873User certificates authenticate users to servers, whereas host certificates
874authenticate server hosts to users.
875To generate a user certificate:
876.Pp
877.Dl $ ssh-keygen -s /path/to/ca_key -I key_id /path/to/user_key.pub
878.Pp
879The resultant certificate will be placed in
880.Pa /path/to/user_key-cert.pub .
881A host certificate requires the
882.Fl h
883option:
884.Pp
885.Dl $ ssh-keygen -s /path/to/ca_key -I key_id -h /path/to/host_key.pub
886.Pp
887The host certificate will be output to
888.Pa /path/to/host_key-cert.pub .
889.Pp
890It is possible to sign using a CA key stored in a PKCS#11 token by
891providing the token library using
892.Fl D
893and identifying the CA key by providing its public half as an argument
894to
895.Fl s :
896.Pp
897.Dl $ ssh-keygen -s ca_key.pub -D libpkcs11.so -I key_id user_key.pub
898.Pp
899Similarly, it is possible for the CA key to be hosted in a
900.Xr ssh-agent 1 .
901This is indicated by the
902.Fl U
903flag and, again, the CA key must be identified by its public half.
904.Pp
905.Dl $ ssh-keygen -Us ca_key.pub -I key_id user_key.pub
906.Pp
907In all cases,
908.Ar key_id
909is a "key identifier" that is logged by the server when the certificate
910is used for authentication.
911.Pp
912Certificates may be limited to be valid for a set of principal (user/host)
913names.
914By default, generated certificates are valid for all users or hosts.
915To generate a certificate for a specified set of principals:
916.Pp
917.Dl $ ssh-keygen -s ca_key -I key_id -n user1,user2 user_key.pub
918.Dl "$ ssh-keygen -s ca_key -I key_id -h -n host.domain host_key.pub"
919.Pp
920Additional limitations on the validity and use of user certificates may
921be specified through certificate options.
922A certificate option may disable features of the SSH session, may be
923valid only when presented from particular source addresses or may
924force the use of a specific command.
925.Pp
926The options that are valid for user certificates are:
927.Pp
928.Bl -tag -width Ds -compact
929.It Ic clear
930Clear all enabled permissions.
931This is useful for clearing the default set of permissions so permissions may
932be added individually.
933.Pp
934.It Ic critical : Ns Ar name Ns Op Ns = Ns Ar contents
935.It Ic extension : Ns Ar name Ns Op Ns = Ns Ar contents
936Includes an arbitrary certificate critical option or extension.
937The specified
938.Ar name
939should include a domain suffix, e.g.\&
940.Dq name@example.com .
941If
942.Ar contents
943is specified then it is included as the contents of the extension/option
944encoded as a string, otherwise the extension/option is created with no
945contents (usually indicating a flag).
946Extensions may be ignored by a client or server that does not recognise them,
947whereas unknown critical options will cause the certificate to be refused.
948.Pp
949.It Ic force-command Ns = Ns Ar command
950Forces the execution of
951.Ar command
952instead of any shell or command specified by the user when
953the certificate is used for authentication.
954.Pp
955.It Ic no-agent-forwarding
956Disable
957.Xr ssh-agent 1
958forwarding (permitted by default).
959.Pp
960.It Ic no-port-forwarding
961Disable port forwarding (permitted by default).
962.Pp
963.It Ic no-pty
964Disable PTY allocation (permitted by default).
965.Pp
966.It Ic no-user-rc
967Disable execution of
968.Pa ~/.ssh/rc
969by
970.Xr sshd 8
971(permitted by default).
972.Pp
973.It Ic no-x11-forwarding
974Disable X11 forwarding (permitted by default).
975.Pp
976.It Ic permit-agent-forwarding
977Allows
978.Xr ssh-agent 1
979forwarding.
980.Pp
981.It Ic permit-port-forwarding
982Allows port forwarding.
983.Pp
984.It Ic permit-pty
985Allows PTY allocation.
986.Pp
987.It Ic permit-user-rc
988Allows execution of
989.Pa ~/.ssh/rc
990by
991.Xr sshd 8 .
992.Pp
993.It Ic permit-X11-forwarding
994Allows X11 forwarding.
995.Pp
996.It Ic no-touch-required
997Do not require signatures made using this key include demonstration
998of user presence (e.g. by having the user touch the authenticator).
999This option only makes sense for the FIDO authenticator algorithms
1000.Cm ecdsa-sk
1001and
1002.Cm ed25519-sk .
1003.Pp
1004.It Ic source-address Ns = Ns Ar address_list
1005Restrict the source addresses from which the certificate is considered valid.
1006The
1007.Ar address_list
1008is a comma-separated list of one or more address/netmask pairs in CIDR
1009format.
1010.Pp
1011.It Ic verify-required
1012Require signatures made using this key indicate that the user was first
1013verified.
1014This option only makes sense for the FIDO authenticator algorithms
1015.Cm ecdsa-sk
1016and
1017.Cm ed25519-sk .
1018Currently PIN authentication is the only supported verification method,
1019but other methods may be supported in the future.
1020.El
1021.Pp
1022At present, no standard options are valid for host keys.
1023.Pp
1024Finally, certificates may be defined with a validity lifetime.
1025The
1026.Fl V
1027option allows specification of certificate start and end times.
1028A certificate that is presented at a time outside this range will not be
1029considered valid.
1030By default, certificates are valid from the
1031.Ux
1032Epoch to the distant future.
1033.Pp
1034For certificates to be used for user or host authentication, the CA
1035public key must be trusted by
1036.Xr sshd 8
1037or
1038.Xr ssh 1 .
1039Please refer to those manual pages for details.
1040.Sh KEY REVOCATION LISTS
1041.Nm
1042is able to manage OpenSSH format Key Revocation Lists (KRLs).
1043These binary files specify keys or certificates to be revoked using a
1044compact format, taking as little as one bit per certificate if they are being
1045revoked by serial number.
1046.Pp
1047KRLs may be generated using the
1048.Fl k
1049flag.
1050This option reads one or more files from the command line and generates a new
1051KRL.
1052The files may either contain a KRL specification (see below) or public keys,
1053listed one per line.
1054Plain public keys are revoked by listing their hash or contents in the KRL and
1055certificates revoked by serial number or key ID (if the serial is zero or
1056not available).
1057.Pp
1058Revoking keys using a KRL specification offers explicit control over the
1059types of record used to revoke keys and may be used to directly revoke
1060certificates by serial number or key ID without having the complete original
1061certificate on hand.
1062A KRL specification consists of lines containing one of the following directives
1063followed by a colon and some directive-specific information.
1064.Bl -tag -width Ds
1065.It Cm serial : Ar serial_number Ns Op - Ns Ar serial_number
1066Revokes a certificate with the specified serial number.
1067Serial numbers are 64-bit values, not including zero and may be expressed
1068in decimal, hex or octal.
1069If two serial numbers are specified separated by a hyphen, then the range
1070of serial numbers including and between each is revoked.
1071The CA key must have been specified on the
1072.Nm
1073command line using the
1074.Fl s
1075option.
1076.It Cm id : Ar key_id
1077Revokes a certificate with the specified key ID string.
1078The CA key must have been specified on the
1079.Nm
1080command line using the
1081.Fl s
1082option.
1083.It Cm key : Ar public_key
1084Revokes the specified key.
1085If a certificate is listed, then it is revoked as a plain public key.
1086.It Cm sha1 : Ar public_key
1087Revokes the specified key by including its SHA1 hash in the KRL.
1088.It Cm sha256 : Ar public_key
1089Revokes the specified key by including its SHA256 hash in the KRL.
1090KRLs that revoke keys by SHA256 hash are not supported by OpenSSH versions
1091prior to 7.9.
1092.It Cm hash : Ar fingerprint
1093Revokes a key using a fingerprint hash, as obtained from a
1094.Xr sshd 8
1095authentication log message or the
1096.Nm
1097.Fl l
1098flag.
1099Only SHA256 fingerprints are supported here and resultant KRLs are
1100not supported by OpenSSH versions prior to 7.9.
1101.El
1102.Pp
1103KRLs may be updated using the
1104.Fl u
1105flag in addition to
1106.Fl k .
1107When this option is specified, keys listed via the command line are merged into
1108the KRL, adding to those already there.
1109.Pp
1110It is also possible, given a KRL, to test whether it revokes a particular key
1111(or keys).
1112The
1113.Fl Q
1114flag will query an existing KRL, testing each key specified on the command line.
1115If any key listed on the command line has been revoked (or an error encountered)
1116then
1117.Nm
1118will exit with a non-zero exit status.
1119A zero exit status will only be returned if no key was revoked.
1120.Sh ALLOWED SIGNERS
1121When verifying signatures,
1122.Nm
1123uses a simple list of identities and keys to determine whether a signature
1124comes from an authorized source.
1125This "allowed signers" file uses a format patterned after the
1126AUTHORIZED_KEYS FILE FORMAT described in
1127.Xr sshd 8 .
1128Each line of the file contains the following space-separated fields:
1129principals, options, keytype, base64-encoded key.
1130Empty lines and lines starting with a
1131.Ql #
1132are ignored as comments.
1133.Pp
1134The principals field is a pattern-list (see PATTERNS in
1135.Xr ssh_config 5 )
1136consisting of one or more comma-separated USER@DOMAIN identity patterns
1137that are accepted for signing.
1138When verifying, the identity presented via the
1139.Fl I
1140option must match a principals pattern in order for the corresponding key to be
1141considered acceptable for verification.
1142.Pp
1143The options (if present) consist of comma-separated option specifications.
1144No spaces are permitted, except within double quotes.
1145The following option specifications are supported (note that option keywords
1146are case-insensitive):
1147.Bl -tag -width Ds
1148.It Cm cert-authority
1149Indicates that this key is accepted as a certificate authority (CA) and
1150that certificates signed by this CA may be accepted for verification.
1151.It Cm namespaces Ns = Ns "namespace-list"
1152Specifies a pattern-list of namespaces that are accepted for this key.
1153If this option is present, the signature namespace embedded in the
1154signature object and presented on the verification command-line must
1155match the specified list before the key will be considered acceptable.
1156.It Cm valid-after Ns = Ns "timestamp"
1157Indicates that the key is valid for use at or after the specified timestamp,
1158which may be a date in YYYYMMDD format or a time in YYYYMMDDHHMM[SS] format.
1159.It Cm valid-before Ns = Ns "timestamp"
1160Indicates that the key is valid for use at or before the specified timestamp.
1161.El
1162.Pp
1163When verifying signatures made by certificates, the expected principal
1164name must match both the principals pattern in the allowed signers file and
1165the principals embedded in the certificate itself.
1166.Pp
1167An example allowed signers file:
1168.Bd -literal -offset 3n
1169# Comments allowed at start of line
1170user1@example.com,user2@example.com ssh-rsa AAAAX1...
1171# A certificate authority, trusted for all principals in a domain.
1172*@example.com cert-authority ssh-ed25519 AAAB4...
1173# A key that is accepted only for file signing.
1174user2@example.com namespaces="file" ssh-ed25519 AAA41...
1175.Ed
1176.Sh ENVIRONMENT
1177.Bl -tag -width Ds
1178.It Ev SSH_SK_PROVIDER
1179Specifies a path to a library that will be used when loading any
1180FIDO authenticator-hosted keys, overriding the default of using
1181the built-in USB HID support.
1182.El
1183.Sh FILES
1184.Bl -tag -width Ds -compact
1185.It Pa ~/.ssh/id_dsa
1186.It Pa ~/.ssh/id_ecdsa
1187.It Pa ~/.ssh/id_ecdsa_sk
1188.It Pa ~/.ssh/id_ed25519
1189.It Pa ~/.ssh/id_ed25519_sk
1190.It Pa ~/.ssh/id_rsa
1191Contains the DSA, ECDSA, authenticator-hosted ECDSA, Ed25519,
1192authenticator-hosted Ed25519 or RSA authentication identity of the user.
1193This file should not be readable by anyone but the user.
1194It is possible to
1195specify a passphrase when generating the key; that passphrase will be
1196used to encrypt the private part of this file using 128-bit AES.
1197This file is not automatically accessed by
1198.Nm
1199but it is offered as the default file for the private key.
1200.Xr ssh 1
1201will read this file when a login attempt is made.
1202.Pp
1203.It Pa ~/.ssh/id_dsa.pub
1204.It Pa ~/.ssh/id_ecdsa.pub
1205.It Pa ~/.ssh/id_ecdsa_sk.pub
1206.It Pa ~/.ssh/id_ed25519.pub
1207.It Pa ~/.ssh/id_ed25519_sk.pub
1208.It Pa ~/.ssh/id_rsa.pub
1209Contains the DSA, ECDSA, authenticator-hosted ECDSA, Ed25519,
1210authenticator-hosted Ed25519 or RSA public key for authentication.
1211The contents of this file should be added to
1212.Pa ~/.ssh/authorized_keys
1213on all machines
1214where the user wishes to log in using public key authentication.
1215There is no need to keep the contents of this file secret.
1216.Pp
1217.It Pa /etc/moduli
1218Contains Diffie-Hellman groups used for DH-GEX.
1219The file format is described in
1220.Xr moduli 5 .
1221.El
1222.Sh SEE ALSO
1223.Xr ssh 1 ,
1224.Xr ssh-add 1 ,
1225.Xr ssh-agent 1 ,
1226.Xr moduli 5 ,
1227.Xr sshd 8
1228.Rs
1229.%R RFC 4716
1230.%T "The Secure Shell (SSH) Public Key File Format"
1231.%D 2006
1232.Re
1233.Sh AUTHORS
1234OpenSSH is a derivative of the original and free
1235ssh 1.2.12 release by Tatu Ylonen.
1236Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos,
1237Theo de Raadt and Dug Song
1238removed many bugs, re-added newer features and
1239created OpenSSH.
1240Markus Friedl contributed the support for SSH
1241protocol versions 1.5 and 2.0.
1242