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