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