xref: /freebsd/crypto/openssh/ssh-keygen.1 (revision a259b98fa211ed87bfee58c575de4e2de94ee0fa)
1.\"	$OpenBSD: ssh-keygen.1,v 1.238 2026/07/01 01:14:39 djm Exp $
2.\"
3.\" Author: Tatu Ylonen <ylo@cs.hut.fi>
4.\" Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5.\"                    All rights reserved
6.\"
7.\" As far as I am concerned, the code I have written for this software
8.\" can be used freely for any purpose.  Any derived versions of this
9.\" software must be clearly marked as such, and if the derived work is
10.\" incompatible with the protocol description in the RFC file, it must be
11.\" called by a name other than "ssh" or "Secure Shell".
12.\"
13.\"
14.\" Copyright (c) 1999,2000 Markus Friedl.  All rights reserved.
15.\" Copyright (c) 1999 Aaron Campbell.  All rights reserved.
16.\" Copyright (c) 1999 Theo de Raadt.  All rights reserved.
17.\"
18.\" Redistribution and use in source and binary forms, with or without
19.\" modification, are permitted provided that the following conditions
20.\" are met:
21.\" 1. Redistributions of source code must retain the above copyright
22.\"    notice, this list of conditions and the following disclaimer.
23.\" 2. Redistributions in binary form must reproduce the above copyright
24.\"    notice, this list of conditions and the following disclaimer in the
25.\"    documentation and/or other materials provided with the distribution.
26.\"
27.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
28.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
31.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
36.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37.\"
38.Dd $Mdocdate: July 1 2026 $
39.Dt SSH-KEYGEN 1
40.Os
41.Sh NAME
42.Nm ssh-keygen
43.Nd OpenSSH authentication key utility
44.Sh SYNOPSIS
45.Nm ssh-keygen
46.Op Fl q
47.Op Fl a Ar rounds
48.Op Fl b Ar bits
49.Op Fl C Ar comment
50.Op Fl f Ar output_keyfile
51.Op Fl m Ar format
52.Op Fl N Ar new_passphrase
53.Op Fl O Ar option
54.Op Fl t Cm ecdsa | ecdsa-sk | ed25519 | ed25519-sk | mldsa44-ed25519 | rsa
55.Op Fl w Ar provider
56.Op Fl Z Ar cipher
57.Nm ssh-keygen
58.Fl p
59.Op Fl a Ar rounds
60.Op Fl f Ar keyfile
61.Op Fl m Ar format
62.Op Fl N Ar new_passphrase
63.Op Fl P Ar old_passphrase
64.Op Fl Z Ar cipher
65.Nm ssh-keygen
66.Fl i
67.Op Fl f Ar input_keyfile
68.Op Fl m Ar key_format
69.Nm ssh-keygen
70.Fl e
71.Op Fl f Ar input_keyfile
72.Op Fl m Ar key_format
73.Nm ssh-keygen
74.Fl y
75.Op Fl f Ar input_keyfile
76.Nm ssh-keygen
77.Fl c
78.Op Fl a Ar rounds
79.Op Fl C Ar comment
80.Op Fl f Ar keyfile
81.Op Fl P Ar passphrase
82.Nm ssh-keygen
83.Fl l
84.Op Fl v
85.Op Fl E Ar fingerprint_hash
86.Op Fl f Ar input_keyfile
87.Nm ssh-keygen
88.Fl B
89.Op Fl f Ar input_keyfile
90.Nm ssh-keygen
91.Fl D Ar pkcs11
92.Nm ssh-keygen
93.Fl F Ar hostname
94.Op Fl lv
95.Op Fl f Ar known_hosts_file
96.Nm ssh-keygen
97.Fl H
98.Op Fl f Ar known_hosts_file
99.Nm ssh-keygen
100.Fl K
101.Op Fl a Ar rounds
102.Op Fl w Ar provider
103.Nm ssh-keygen
104.Fl R Ar hostname
105.Op Fl f Ar known_hosts_file
106.Nm ssh-keygen
107.Fl r Ar hostname
108.Op Fl g
109.Op Fl f Ar input_keyfile
110.Nm ssh-keygen
111.Fl M Cm generate
112.Op Fl O Ar option
113.Ar output_file
114.Nm ssh-keygen
115.Fl M Cm screen
116.Op Fl f Ar input_file
117.Op Fl O Ar option
118.Ar output_file
119.Nm ssh-keygen
120.Fl I Ar certificate_identity
121.Fl s Ar ca_key
122.Op Fl hU
123.Op Fl D Ar pkcs11_provider
124.Op Fl n Ar principals
125.Op Fl O Ar option
126.Op Fl V Ar validity_interval
127.Op Fl z Ar serial_number
128.Ar
129.Nm ssh-keygen
130.Fl L
131.Op Fl f Ar input_keyfile
132.Nm ssh-keygen
133.Fl A
134.Op Fl a Ar rounds
135.Op Fl f Ar prefix_path
136.Nm ssh-keygen
137.Fl k
138.Fl f Ar krl_file
139.Op Fl u
140.Op Fl s Ar ca_public
141.Op Fl z Ar version_number
142.Ar
143.Nm ssh-keygen
144.Fl Q
145.Op Fl l
146.Fl f Ar krl_file
147.Ar
148.Nm ssh-keygen
149.Fl Y Cm find-principals
150.Op Fl O Ar option
151.Fl s Ar signature_file
152.Fl f Ar allowed_signers_file
153.Nm ssh-keygen
154.Fl Y Cm match-principals
155.Fl I Ar signer_identity
156.Fl f Ar allowed_signers_file
157.Nm ssh-keygen
158.Fl Y Cm check-novalidate
159.Op Fl O Ar option
160.Fl n Ar namespace
161.Fl s Ar signature_file
162.Nm ssh-keygen
163.Fl Y Cm sign
164.Op Fl O Ar option
165.Fl f Ar key_file
166.Fl n Ar namespace
167.Ar
168.Nm ssh-keygen
169.Fl Y Cm verify
170.Op Fl O Ar option
171.Fl f Ar allowed_signers_file
172.Fl I Ar signer_identity
173.Fl n Ar namespace
174.Fl s Ar signature_file
175.Op Fl r Ar revocation_file
176.Sh DESCRIPTION
177.Nm
178generates, manages and converts authentication keys for
179.Xr ssh 1 .
180.Nm
181can create keys for use by SSH protocol version 2.
182.Pp
183The type of key to be generated is specified with the
184.Fl t
185option.
186If invoked without any arguments,
187.Nm
188will generate an Ed25519 key.
189.Pp
190.Nm
191is also used to generate groups for use in Diffie-Hellman group
192exchange (DH-GEX).
193See the
194.Sx MODULI GENERATION
195section for details.
196.Pp
197Finally,
198.Nm
199can be used to generate and update Key Revocation Lists, and to test whether
200given keys have been revoked by one.
201See the
202.Sx KEY REVOCATION LISTS
203section for details.
204.Pp
205Normally each user wishing to use SSH
206with public key authentication runs this once to create the authentication
207key in
208.Pa ~/.ssh/id_ecdsa ,
209.Pa ~/.ssh/id_ecdsa_sk ,
210.Pa ~/.ssh/id_ed25519 ,
211.Pa ~/.ssh/id_ed25519_sk ,
212.Pa ~/.ssh/id_mldsa44-ed25519
213or
214.Pa ~/.ssh/id_rsa .
215Additionally, the system administrator may use this to generate host keys,
216as seen in
217.Pa /etc/rc .
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, mldsa44-ed25519 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 .
553.It Fl R Ar hostname | [hostname]:port
554Removes all keys belonging to the specified
555.Ar hostname
556(with optional port number)
557from a
558.Pa known_hosts
559file.
560This option is useful to delete hashed hosts (see the
561.Fl H
562option above).
563.It Fl r Ar hostname
564Print the SSHFP fingerprint resource record named
565.Ar hostname
566for the specified public key file.
567.It Fl s Ar ca_key
568Certify (sign) a public key using the specified CA key.
569See the
570.Sx CERTIFICATES
571section for details.
572.Pp
573When generating a KRL,
574.Fl s
575specifies a path to a CA public key file used to revoke certificates directly
576by key ID or serial number.
577See the
578.Sx KEY REVOCATION LISTS
579section for details.
580.It Fl t Cm ecdsa | ecdsa-sk | ed25519 | ed25519-sk | mldsa44-ed25519 | rsa
581Specifies the type of key to create.
582The possible values are
583.Dq ecdsa ,
584.Dq ecdsa-sk ,
585.Dq ed25519 (the default),
586.Dq ed25519-sk ,
587.Dq mldsa44-ed25519
588or
589.Dq rsa .
590.Pp
591This flag may also be used to specify the desired signature type when
592signing certificates using an RSA CA key.
593The available RSA signature variants are
594.Dq ssh-rsa
595(SHA1 signatures, not recommended),
596.Dq rsa-sha2-256 ,
597and
598.Dq rsa-sha2-512
599(the default for RSA keys).
600.It Fl U
601When used in combination with
602.Fl s
603or
604.Fl Y Cm sign ,
605this option indicates that a CA key resides in an
606.Xr ssh-agent 1 .
607See the
608.Sx CERTIFICATES
609section for more information.
610.It Fl u
611Update a KRL.
612When specified with
613.Fl k ,
614keys listed via the command line are added to the existing KRL rather than
615a new KRL being created.
616.It Fl V Ar validity_interval
617Specify a validity interval when signing a certificate.
618A validity interval may consist of a single time, indicating that the
619certificate is valid beginning now and expiring at that time, or may consist
620of two times separated by a colon to indicate an explicit time interval.
621.Pp
622The start time may be specified as:
623.Bl -bullet -compact
624.It
625The string
626.Dq always
627to indicate the certificate has no specified start time.
628.It
629A date or time in the system time zone formatted as YYYYMMDD or
630YYYYMMDDHHMM[SS].
631.It
632A date or time in the UTC time zone as YYYYMMDDZ or YYYYMMDDHHMM[SS]Z.
633.It
634A relative time before the current system time consisting of a minus sign
635followed by an interval in the format described in the
636TIME FORMATS section of
637.Xr sshd_config 5 .
638.It
639A raw seconds since epoch (Jan 1 1970 00:00:00 UTC) as a hexadecimal
640number beginning with
641.Dq 0x .
642.El
643.Pp
644The end time may be specified similarly to the start time:
645.Bl -bullet -compact
646.It
647The string
648.Dq forever
649to indicate the certificate has no specified end time.
650.It
651A date or time in the system time zone formatted as YYYYMMDD or
652YYYYMMDDHHMM[SS].
653.It
654A date or time in the UTC time zone as YYYYMMDDZ or YYYYMMDDHHMM[SS]Z.
655.It
656A relative time after the current system time consisting of a plus sign
657followed by an interval in the format described in the
658TIME FORMATS section of
659.Xr sshd_config 5 .
660.It
661A raw seconds since epoch (Jan 1 1970 00:00:00 UTC) as a hexadecimal
662number beginning with
663.Dq 0x .
664.El
665.Pp
666For example:
667.Bl -tag -width Ds
668.It +52w1d
669Valid from now to 52 weeks and one day from now.
670.It -4w:+4w
671Valid from four weeks ago to four weeks from now.
672.It 20100101123000:20110101123000
673Valid from 12:30 PM, January 1st, 2010 to 12:30 PM, January 1st, 2011.
674.It 20100101123000Z:20110101123000Z
675Similar, but interpreted in the UTC time zone rather than the system time zone.
676.It -1d:20110101
677Valid from yesterday to midnight, January 1st, 2011.
678.It 0x1:0x2000000000
679Valid from roughly early 1970 to May 2033.
680.It -1m:forever
681Valid from one minute ago and never expiring.
682.El
683.It Fl v
684Verbose mode.
685Causes
686.Nm
687to print debugging messages about its progress.
688This is helpful for debugging moduli generation.
689Multiple
690.Fl v
691options increase the verbosity.
692The maximum is 3.
693.It Fl w Ar provider
694Specifies a path to a library that will be used when creating
695FIDO authenticator-hosted keys, overriding the default of using
696the internal USB HID support.
697.It Fl Y Cm find-principals
698Find the principal(s) associated with the public key of a signature,
699provided using the
700.Fl s
701flag in an authorized signers file provided using the
702.Fl f
703flag.
704The format of the allowed signers file is documented in the
705.Sx ALLOWED SIGNERS
706section below.
707If one or more matching principals are found, they are returned on
708standard output.
709.It Fl Y Cm match-principals
710Find principal matching the principal name provided using the
711.Fl I
712flag in the authorized signers file specified using the
713.Fl f
714flag.
715If one or more matching principals are found, they are returned on
716standard output.
717.It Fl Y Cm check-novalidate
718Checks that a signature generated using
719.Nm
720.Fl Y Cm sign
721has a valid structure.
722This does not validate if a signature comes from an authorized signer.
723When testing a signature,
724.Nm
725accepts a message on standard input and a signature namespace using
726.Fl n .
727A file containing the corresponding signature must also be supplied using the
728.Fl s
729flag.
730Successful testing of the signature is signalled by
731.Nm
732returning a zero exit status.
733.It Fl Y Cm sign
734Cryptographically sign a file or some data using an SSH key.
735When signing,
736.Nm
737accepts zero or more files to sign on the command-line - if no files
738are specified then
739.Nm
740will sign data presented on standard input.
741Signatures are written to the path of the input file with
742.Dq .sig
743appended, or to standard output if the message to be signed was read from
744standard input.
745.Pp
746The key used for signing is specified using the
747.Fl f
748option and may refer to either a private key, or a public key with the private
749half available via
750.Xr ssh-agent 1 .
751An additional signature namespace, used to prevent signature confusion across
752different domains of use (e.g. file signing vs email signing) must be provided
753via the
754.Fl n
755flag.
756Namespaces are arbitrary strings, and may include:
757.Dq file
758for file signing,
759.Dq email
760for email signing.
761For custom uses, it is recommended to use names following a
762NAMESPACE@YOUR.DOMAIN pattern to generate unambiguous namespaces.
763.It Fl Y Cm verify
764Request to verify a signature generated using
765.Nm
766.Fl Y Cm sign
767as described above.
768When verifying a signature,
769.Nm
770accepts a message on standard input and a signature namespace using
771.Fl n .
772A file containing the corresponding signature must also be supplied using the
773.Fl s
774flag, along with the identity of the signer using
775.Fl I
776and a list of allowed signers via the
777.Fl f
778flag.
779The format of the allowed signers file is documented in the
780.Sx ALLOWED SIGNERS
781section below.
782A file containing revoked keys can be passed using the
783.Fl r
784flag.
785The revocation file may be a KRL or a one-per-line list of public keys.
786Successful verification by an authorized signer is signalled by
787.Nm
788returning a zero exit status.
789.It Fl y
790This option will read a private
791OpenSSH format file and print an OpenSSH public key to stdout.
792.It Fl Z Ar cipher
793Specifies the cipher to use for encryption when writing an OpenSSH-format
794private key file.
795The list of available ciphers may be obtained using
796.Qq ssh -Q cipher .
797The default is
798.Dq aes256-ctr .
799.It Fl z Ar serial_number
800Specifies a serial number to be embedded in the certificate to distinguish
801this certificate from others from the same CA.
802If the
803.Ar serial_number
804is prefixed with a
805.Sq +
806character, then the serial number will be incremented for each certificate
807signed on a single command-line.
808The default serial number is zero.
809.Pp
810When generating a KRL, the
811.Fl z
812flag is used to specify a KRL version number.
813.El
814.Sh MODULI GENERATION
815.Nm
816may be used to generate groups for the Diffie-Hellman Group Exchange
817(DH-GEX) protocol.
818Generating these groups is a two-step process: first, candidate
819primes are generated using a fast, but memory intensive process.
820These candidate primes are then tested for suitability (a CPU-intensive
821process).
822.Pp
823Generation of primes is performed using the
824.Fl M Cm generate
825option.
826The desired length of the primes may be specified by the
827.Fl O Cm bits
828option.
829For example:
830.Pp
831.Dl # ssh-keygen -M generate -O bits=2048 moduli-2048.candidates
832.Pp
833By default, the search for primes begins at a random point in the
834desired length range.
835This may be overridden using the
836.Fl O Cm start
837option, which specifies a different start point (in hex).
838.Pp
839Once a set of candidates have been generated, they must be screened for
840suitability.
841This may be performed using the
842.Fl M Cm screen
843option.
844In this mode
845.Nm
846will read candidates from standard input (or a file specified using the
847.Fl f
848option).
849For example:
850.Pp
851.Dl # ssh-keygen -M screen -f moduli-2048.candidates moduli-2048
852.Pp
853By default, each candidate will be subjected to 100 primality tests.
854This may be overridden using the
855.Fl O Cm prime-tests
856option.
857The DH generator value will be chosen automatically for the
858prime under consideration.
859If a specific generator is desired, it may be requested using the
860.Fl O Cm generator
861option.
862Valid generator values are 2, 3, and 5.
863.Pp
864Screened DH groups may be installed in
865.Pa /etc/moduli .
866It is important that this file contains moduli of a range of bit lengths.
867.Pp
868A number of options are available for moduli generation and screening via the
869.Fl O
870flag:
871.Bl -tag -width Ds
872.It Ic lines Ns = Ns Ar number
873Exit after screening the specified number of lines while performing DH
874candidate screening.
875.It Ic start-line Ns = Ns Ar line-number
876Start screening at the specified line number while performing DH candidate
877screening.
878.It Ic checkpoint Ns = Ns Ar filename
879Write the last line processed to the specified file while performing DH
880candidate screening.
881This will be used to skip lines in the input file that have already been
882processed if the job is restarted.
883.It Ic start Ns = Ns Ar hex-value
884Specify start point (in hex) when generating candidate moduli for DH-GEX.
885.It Ic generator Ns = Ns Ar value
886Specify desired generator (in decimal) when testing candidate moduli for DH-GEX.
887.El
888.Sh CERTIFICATES
889.Nm
890supports signing of keys to produce certificates that may be used for
891user or host authentication.
892Certificates consist of a public key, some identity information, zero or
893more principal (user or host) names and a set of options that
894are signed by a Certification Authority (CA) key.
895Clients or servers may then trust only the CA key and verify its signature
896on a certificate rather than trusting many user/host keys.
897Note that OpenSSH certificates are a different, and much simpler, format to
898the X.509 certificates used in
899.Xr ssl 8 .
900.Pp
901.Nm
902supports two types of certificates: user and host.
903User certificates authenticate users to servers, whereas host certificates
904authenticate server hosts to users.
905To generate a user certificate:
906.Pp
907.Dl $ ssh-keygen -s /path/to/ca_key -I id -n user \e
908.Dl \ \ \ \ \ \ /path/to/user_key.pub
909.Pp
910The resultant certificate will be placed in
911.Pa /path/to/user_key-cert.pub .
912The argument to
913.Fl I
914is a key identifier that will be used in logs and may be used to revoke
915keys.
916The argument to
917.Fl n
918is one or more (comma-separated) principals, typically usernames, that
919the certificate represents.
920A host certificate requires the
921.Fl h
922option:
923.Pp
924.Dl $ ssh-keygen -s /path/to/ca_key -I id -h -n foo.example.org \e
925.Dl \ \ \ \ \ \ /path/to/host_key.pub
926.Pp
927For host certificates, the principals specified using the
928.Fl n
929argument are hostnames and may contain wildcard characters.
930.Pp
931The host certificate will be output to
932.Pa /path/to/host_key-cert.pub .
933.Pp
934It is possible to sign using a CA key stored in a PKCS#11 token by
935providing the token library using
936.Fl D
937and identifying the CA key by providing its public half as an argument
938to
939.Fl s :
940.Pp
941.Dl $ ssh-keygen -s ca_key.pub -D libpkcs11.so -I id -n user \e
942.Dl \ \ \ \ \ \ user_key.pub
943.Pp
944Similarly, it is possible for the CA key to be hosted in an
945.Xr ssh-agent 1 .
946This is indicated by the
947.Fl U
948flag and, again, the CA key must be identified by its public half.
949.Pp
950.Dl $ ssh-keygen -Us ca_key.pub -I id -n user user_key.pub
951.Pp
952In all cases,
953.Ar key_id
954is a "key identifier" that is logged by the server when the certificate
955is used for authentication.
956.Pp
957Certificates are limited to be valid for a set of principal (user/host)
958names.
959To generate a certificate for a specified set of principals:
960.Pp
961.Dl $ ssh-keygen -s ca_key -I id -n user1,user2 user_key.pub
962.Dl $ ssh-keygen -s ca_key -I id -h -n host.domain host_key.pub
963.Pp
964Additional limitations on the validity and use of user certificates may
965be specified through certificate options.
966A certificate option may disable features of the SSH session, may be
967valid only when presented from particular source addresses or may
968force the use of a specific command.
969.Pp
970The options that are valid for user certificates are:
971.Pp
972.Bl -tag -width Ds -compact
973.It Ic clear
974Clear all enabled permissions.
975This is useful for clearing the default set of permissions so permissions may
976be added individually.
977.Pp
978.It Ic critical : Ns Ar name Ns Op Ns = Ns Ar contents
979.It Ic extension : Ns Ar name Ns Op Ns = Ns Ar contents
980Includes an arbitrary certificate critical option or extension.
981The specified
982.Ar name
983should include a domain suffix, e.g.\&
984.Dq name@example.com .
985If
986.Ar contents
987is specified then it is included as the contents of the extension/option
988encoded as a string, otherwise the extension/option is created with no
989contents (usually indicating a flag).
990Extensions may be ignored by a client or server that does not recognise them,
991whereas unknown critical options will cause the certificate to be refused.
992.Pp
993.It Ic force-command Ns = Ns Ar command
994Forces the execution of
995.Ar command
996instead of any shell or command specified by the user when
997the certificate is used for authentication.
998.Pp
999.It Ic no-agent-forwarding
1000Disable
1001.Xr ssh-agent 1
1002forwarding (permitted by default).
1003.Pp
1004.It Ic no-port-forwarding
1005Disable port forwarding (permitted by default).
1006.Pp
1007.It Ic no-pty
1008Disable PTY allocation (permitted by default).
1009.Pp
1010.It Ic no-user-rc
1011Disable execution of
1012.Pa ~/.ssh/rc
1013by
1014.Xr sshd 8
1015(permitted by default).
1016.Pp
1017.It Ic no-x11-forwarding
1018Disable X11 forwarding (permitted by default).
1019.Pp
1020.It Ic permit-agent-forwarding
1021Allows
1022.Xr ssh-agent 1
1023forwarding.
1024.Pp
1025.It Ic permit-port-forwarding
1026Allows port forwarding.
1027.Pp
1028.It Ic permit-pty
1029Allows PTY allocation.
1030.Pp
1031.It Ic permit-user-rc
1032Allows execution of
1033.Pa ~/.ssh/rc
1034by
1035.Xr sshd 8 .
1036.Pp
1037.It Ic permit-X11-forwarding
1038Allows X11 forwarding.
1039.Pp
1040.It Ic no-touch-required
1041Do not require signatures made using this key include demonstration
1042of user presence (e.g. by having the user touch the authenticator).
1043This option only makes sense for the FIDO authenticator algorithms
1044.Cm ecdsa-sk
1045and
1046.Cm ed25519-sk .
1047.Pp
1048.It Ic source-address Ns = Ns Ar address_list
1049Restrict the source addresses from which the certificate is considered valid.
1050The
1051.Ar address_list
1052is a comma-separated list of one or more address/netmask pairs in CIDR
1053format.
1054.Pp
1055.It Ic verify-required
1056Require signatures made using this key indicate that the user was first
1057verified, e.g. by PIN or on-token biometrics.
1058This option only makes sense for the FIDO authenticator algorithms
1059.Cm ecdsa-sk
1060and
1061.Cm ed25519-sk .
1062.El
1063.Pp
1064At present, no standard options are valid for host keys.
1065.Pp
1066Finally, certificates may be defined with a validity lifetime.
1067The
1068.Fl V
1069option allows specification of certificate start and end times.
1070A certificate that is presented at a time outside this range will not be
1071considered valid.
1072By default, certificates are valid from the
1073.Ux
1074Epoch to the distant future.
1075.Pp
1076For certificates to be used for user or host authentication, the CA
1077public key must be trusted by
1078.Xr sshd 8
1079or
1080.Xr ssh 1 .
1081Refer to those manual pages for details.
1082.Sh FIDO AUTHENTICATOR
1083.Nm
1084is able to generate FIDO authenticator-backed keys, after which
1085they may be used much like any other key type supported by OpenSSH, so
1086long as the hardware authenticator is attached when the keys are used.
1087FIDO authenticators generally require the user to explicitly authorise
1088operations by touching or tapping them.
1089FIDO keys consist of two parts: a key handle part stored in the
1090private key file on disk, and a per-device private key that is unique
1091to each FIDO authenticator and that cannot be exported from the
1092authenticator hardware.
1093These are combined by the hardware at authentication time to derive
1094the real key that is used to sign authentication challenges.
1095Supported key types are
1096.Cm ecdsa-sk
1097and
1098.Cm ed25519-sk .
1099.Pp
1100The options that are valid for FIDO keys are:
1101.Bl -tag -width Ds
1102.It Cm application
1103Override the default FIDO application/origin string of
1104.Dq ssh: .
1105This may be useful when generating host or domain-specific resident keys.
1106The specified application string must begin with
1107.Dq ssh: .
1108.It Cm challenge Ns = Ns Ar path
1109Specifies a path to a challenge string that will be passed to the
1110FIDO authenticator during key generation.
1111The challenge string may be used as part of an out-of-band
1112protocol for key enrollment
1113(a random challenge is used by default).
1114.It Cm device
1115Explicitly specify a
1116.Xr fido 4
1117device to use, rather than letting the authenticator middleware select one.
1118.It Cm no-touch-required
1119Indicate that the generated private key should not require touch
1120events (user presence) when making signatures.
1121Note that
1122.Xr sshd 8
1123will refuse such signatures by default, unless overridden via
1124an authorized_keys option.
1125.It Cm resident
1126Indicate that the key handle should be stored on the FIDO
1127authenticator itself.
1128This makes it easier to use the authenticator on multiple computers.
1129Resident keys may be supported on FIDO2 authenticators and typically
1130require that a PIN be set on the authenticator prior to generation.
1131Resident keys may be loaded off the authenticator using
1132.Xr ssh-add 1 .
1133Storing both parts of a key on a FIDO authenticator increases the likelihood
1134of an attacker being able to use a stolen authenticator device.
1135.It Cm user
1136A username to be associated with a resident key,
1137overriding the empty default username.
1138Specifying a username may be useful when generating multiple resident keys
1139for the same application name.
1140.It Cm verify-required
1141Indicate that this private key should require user verification for
1142each signature.
1143Not all FIDO authenticators support this option.
1144Currently PIN authentication is the only supported verification method,
1145but other methods may be supported in the future.
1146.It Cm write-attestation Ns = Ns Ar path
1147May be used at key generation time to record the attestation data
1148returned from FIDO authenticators during key generation.
1149This information is potentially sensitive.
1150By default, this information is discarded.
1151.El
1152.Sh KEY REVOCATION LISTS
1153.Nm
1154is able to manage OpenSSH format Key Revocation Lists (KRLs).
1155These binary files specify keys or certificates to be revoked using a
1156compact format, taking as little as one bit per certificate if they are being
1157revoked by serial number.
1158.Pp
1159KRLs may be generated using the
1160.Fl k
1161flag.
1162This option reads one or more files from the command line and generates a new
1163KRL.
1164The files may either contain a KRL specification (see below) or public keys,
1165listed one per line.
1166Plain public keys are revoked by listing their hash or contents in the KRL and
1167certificates revoked by serial number or key ID (if the serial is zero or
1168not available).
1169.Pp
1170Revoking keys using a KRL specification offers explicit control over the
1171types of record used to revoke keys and may be used to directly revoke
1172certificates by serial number or key ID without having the complete original
1173certificate on hand.
1174A KRL specification consists of lines containing one of the following directives
1175followed by a colon and some directive-specific information.
1176.Bl -tag -width Ds
1177.It Cm serial : Ar serial_number Ns Op - Ns Ar serial_number
1178Revokes a certificate with the specified serial number.
1179Serial numbers are 64-bit values, not including zero and may be expressed
1180in decimal, hex or octal.
1181If two serial numbers are specified separated by a hyphen, then the range
1182of serial numbers including and between each is revoked.
1183The CA key must have been specified on the
1184.Nm
1185command line using the
1186.Fl s
1187option.
1188.It Cm id : Ar key_id
1189Revokes a certificate with the specified key ID string.
1190The CA key must have been specified on the
1191.Nm
1192command line using the
1193.Fl s
1194option.
1195.It Cm key : Ar public_key
1196Revokes the specified key.
1197If a certificate is listed, then it is revoked as a plain public key.
1198.It Cm sha1 : Ar public_key
1199Revokes the specified key by including its SHA1 hash in the KRL.
1200.It Cm sha256 : Ar public_key
1201Revokes the specified key by including its SHA256 hash in the KRL.
1202KRLs that revoke keys by SHA256 hash are not supported by OpenSSH versions
1203prior to 7.9.
1204.It Cm hash : Ar fingerprint
1205Revokes a key using a fingerprint hash, as obtained from an
1206.Xr sshd 8
1207authentication log message or the
1208.Nm
1209.Fl l
1210flag.
1211Only SHA256 fingerprints are supported here and resultant KRLs are
1212not supported by OpenSSH versions prior to 7.9.
1213.El
1214.Pp
1215KRLs may be updated using the
1216.Fl u
1217flag in addition to
1218.Fl k .
1219When this option is specified, keys listed via the command line are merged into
1220the KRL, adding to those already there.
1221.Pp
1222It is also possible, given a KRL, to test whether it revokes a particular key
1223(or keys).
1224The
1225.Fl Q
1226flag will query an existing KRL, testing each key specified on the command line.
1227If any key listed on the command line has been revoked (or an error encountered)
1228then
1229.Nm
1230will exit with a non-zero exit status.
1231A zero exit status will only be returned if no key was revoked.
1232.Sh ALLOWED SIGNERS
1233When verifying signatures,
1234.Nm
1235uses a simple list of identities and keys to determine whether a signature
1236comes from an authorized source.
1237This "allowed signers" file uses a format patterned after the
1238AUTHORIZED_KEYS FILE FORMAT described in
1239.Xr sshd 8 .
1240Each line of the file contains the following space-separated fields:
1241principals, options, keytype, base64-encoded key.
1242Empty lines and lines starting with a
1243.Ql #
1244are ignored as comments.
1245.Pp
1246The principals field is a pattern-list (see PATTERNS in
1247.Xr ssh_config 5 )
1248consisting of one or more comma-separated USER@DOMAIN identity patterns
1249that are accepted for signing.
1250When verifying, the identity presented via the
1251.Fl I
1252option must match a principals pattern in order for the corresponding key to be
1253considered acceptable for verification.
1254.Pp
1255The options (if present) consist of comma-separated option specifications.
1256No spaces are permitted, except within double quotes.
1257The following option specifications are supported (note that option keywords
1258are case-insensitive):
1259.Bl -tag -width Ds
1260.It Cm cert-authority
1261Indicates that this key is accepted as a certificate authority (CA) and
1262that certificates signed by this CA may be accepted for verification.
1263.It Cm namespaces Ns = Ns "namespace-list"
1264Specifies a pattern-list of namespaces that are accepted for this key.
1265If this option is present, the signature namespace embedded in the
1266signature object and presented on the verification command-line must
1267match the specified list before the key will be considered acceptable.
1268.It Cm valid-after Ns = Ns "timestamp"
1269Indicates that the key is valid for use at or after the specified timestamp,
1270which may be a date or time in the YYYYMMDD[Z] or YYYYMMDDHHMM[SS][Z] formats.
1271Dates and times will be interpreted in the current system time zone unless
1272suffixed with a Z character, which causes them to be interpreted in the UTC
1273time zone.
1274.It Cm valid-before Ns = Ns "timestamp"
1275Indicates that the key is valid for use at or before the specified timestamp.
1276.El
1277.Pp
1278When verifying signatures made by certificates, the expected principal
1279name must match both the principals pattern in the allowed signers file and
1280the principals embedded in the certificate itself.
1281.Pp
1282An example allowed signers file:
1283.Bd -literal -offset 3n
1284# Comments allowed at start of line
1285user1@example.com,user2@example.com ssh-rsa AAAAX1...
1286# A certificate authority, trusted for all principals in a domain.
1287*@example.com cert-authority ssh-ed25519 AAAB4...
1288# A key that is accepted only for file signing.
1289user2@example.com namespaces="file" ssh-ed25519 AAA41...
1290.Ed
1291.Sh ENVIRONMENT
1292.Bl -tag -width Ds
1293.It Ev SSH_SK_PROVIDER
1294Specifies a path to a library that will be used when loading any
1295FIDO authenticator-hosted keys, overriding the default of using
1296the built-in USB HID support.
1297.El
1298.Sh FILES
1299.Bl -tag -width Ds -compact
1300.It Pa ~/.ssh/id_ecdsa
1301.It Pa ~/.ssh/id_ecdsa_sk
1302.It Pa ~/.ssh/id_ed25519
1303.It Pa ~/.ssh/id_ed25519_sk
1304.It Pa ~/.ssh/id_mldsa44-ed25519
1305.It Pa ~/.ssh/id_rsa
1306Contains the ECDSA, authenticator-hosted ECDSA, Ed25519,
1307authenticator-hosted Ed25519 or RSA authentication identity of the user.
1308This file should not be readable by anyone but the user.
1309It is possible to
1310specify a passphrase when generating the key; that passphrase will be
1311used to encrypt the private part of this file using 128-bit AES.
1312This file is not automatically accessed by
1313.Nm
1314but it is offered as the default file for the private key.
1315.Xr ssh 1
1316will read this file when a login attempt is made.
1317.Pp
1318.It Pa ~/.ssh/id_ecdsa.pub
1319.It Pa ~/.ssh/id_ecdsa_sk.pub
1320.It Pa ~/.ssh/id_ed25519.pub
1321.It Pa ~/.ssh/id_ed25519_sk.pub
1322.It Pa ~/.ssh/id_mldsa44-ed25519.pub
1323.It Pa ~/.ssh/id_rsa.pub
1324Contains the ECDSA, authenticator-hosted ECDSA, Ed25519,
1325authenticator-hosted Ed25519 or RSA public key for authentication.
1326The contents of this file should be added to
1327.Pa ~/.ssh/authorized_keys
1328on all machines
1329where the user wishes to log in using public key authentication.
1330There is no need to keep the contents of this file secret.
1331.Pp
1332.It Pa /etc/moduli
1333Contains Diffie-Hellman groups used for DH-GEX.
1334The file format is described in
1335.Xr moduli 5 .
1336.El
1337.Sh SEE ALSO
1338.Xr ssh 1 ,
1339.Xr ssh-add 1 ,
1340.Xr ssh-agent 1 ,
1341.Xr moduli 5 ,
1342.Xr sshd 8
1343.Rs
1344.%R RFC 4716
1345.%T "The Secure Shell (SSH) Public Key File Format"
1346.%D 2006
1347.Re
1348.Sh AUTHORS
1349OpenSSH is a derivative of the original and free
1350ssh 1.2.12 release by Tatu Ylonen.
1351Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos,
1352Theo de Raadt and Dug Song
1353removed many bugs, re-added newer features and
1354created OpenSSH.
1355Markus Friedl contributed the support for SSH
1356protocol versions 1.5 and 2.0.
1357