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