Annotation of src/usr.bin/ssh/ssh-keygen.1, Revision 1.172
1.172 ! jmc 1: .\" $OpenBSD: ssh-keygen.1,v 1.171 2019/10/03 17:07:50 jmc Exp $
1.1 deraadt 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: .\"
1.22 deraadt 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: .\"
1.33 deraadt 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.
1.22 deraadt 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.
1.1 deraadt 26: .\"
1.22 deraadt 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.
1.1 deraadt 37: .\"
1.172 ! jmc 38: .Dd $Mdocdate: October 3 2019 $
1.2 deraadt 39: .Dt SSH-KEYGEN 1
40: .Os
41: .Sh NAME
42: .Nm ssh-keygen
1.37 markus 43: .Nd authentication key generation, management and conversion
1.2 deraadt 44: .Sh SYNOPSIS
45: .Nm ssh-keygen
1.25 markus 46: .Op Fl q
1.2 deraadt 47: .Op Fl b Ar bits
48: .Op Fl C Ar comment
1.20 markus 49: .Op Fl f Ar output_keyfile
1.155 djm 50: .Op Fl m Ar format
1.171 jmc 51: .Op Fl N Ar new_passphrase
52: .Op Fl t Cm dsa | ecdsa | ed25519 | rsa
1.2 deraadt 53: .Nm ssh-keygen
54: .Fl p
1.9 markus 55: .Op Fl f Ar keyfile
1.155 djm 56: .Op Fl m Ar format
1.171 jmc 57: .Op Fl N Ar new_passphrase
58: .Op Fl P Ar old_passphrase
1.2 deraadt 59: .Nm ssh-keygen
1.37 markus 60: .Fl i
1.171 jmc 61: .Op Fl f Ar input_keyfile
1.95 djm 62: .Op Fl m Ar key_format
1.16 deraadt 63: .Nm ssh-keygen
1.37 markus 64: .Fl e
1.171 jmc 65: .Op Fl f Ar input_keyfile
1.95 djm 66: .Op Fl m Ar key_format
1.16 deraadt 67: .Nm ssh-keygen
1.17 markus 68: .Fl y
1.20 markus 69: .Op Fl f Ar input_keyfile
1.17 markus 70: .Nm ssh-keygen
1.2 deraadt 71: .Fl c
72: .Op Fl C Ar comment
1.9 markus 73: .Op Fl f Ar keyfile
1.171 jmc 74: .Op Fl P Ar passphrase
1.9 markus 75: .Nm ssh-keygen
76: .Fl l
1.125 naddy 77: .Op Fl v
1.124 djm 78: .Op Fl E Ar fingerprint_hash
1.35 markus 79: .Op Fl f Ar input_keyfile
80: .Nm ssh-keygen
81: .Fl B
1.20 markus 82: .Op Fl f Ar input_keyfile
1.48 jakob 83: .Nm ssh-keygen
1.82 jmc 84: .Fl D Ar pkcs11
1.48 jakob 85: .Nm ssh-keygen
1.64 djm 86: .Fl F Ar hostname
1.170 jmc 87: .Op Fl lv
1.64 djm 88: .Op Fl f Ar known_hosts_file
89: .Nm ssh-keygen
90: .Fl H
91: .Op Fl f Ar known_hosts_file
92: .Nm ssh-keygen
93: .Fl R Ar hostname
94: .Op Fl f Ar known_hosts_file
1.57 jakob 95: .Nm ssh-keygen
96: .Fl r Ar hostname
1.170 jmc 97: .Op Fl g
1.57 jakob 98: .Op Fl f Ar input_keyfile
1.60 djm 99: .Nm ssh-keygen
100: .Fl G Ar output_file
1.61 djm 101: .Op Fl v
1.60 djm 102: .Op Fl b Ar bits
103: .Op Fl M Ar memory
104: .Op Fl S Ar start_point
105: .Nm ssh-keygen
1.171 jmc 106: .Fl f Ar input_file
1.60 djm 107: .Fl T Ar output_file
1.61 djm 108: .Op Fl v
1.117 djm 109: .Op Fl a Ar rounds
1.109 dtucker 110: .Op Fl J Ar num_lines
111: .Op Fl j Ar start_line
1.108 dtucker 112: .Op Fl K Ar checkpt
1.60 djm 113: .Op Fl W Ar generator
1.84 djm 114: .Nm ssh-keygen
1.171 jmc 115: .Fl I Ar certificate_identity
1.84 djm 116: .Fl s Ar ca_key
1.170 jmc 117: .Op Fl hU
1.142 djm 118: .Op Fl D Ar pkcs11_provider
1.84 djm 119: .Op Fl n Ar principals
1.93 djm 120: .Op Fl O Ar option
1.84 djm 121: .Op Fl V Ar validity_interval
1.93 djm 122: .Op Fl z Ar serial_number
1.84 djm 123: .Ar
1.86 djm 124: .Nm ssh-keygen
125: .Fl L
126: .Op Fl f Ar input_keyfile
1.102 stevesk 127: .Nm ssh-keygen
128: .Fl A
1.143 djm 129: .Op Fl f Ar prefix_path
1.111 djm 130: .Nm ssh-keygen
131: .Fl k
132: .Fl f Ar krl_file
133: .Op Fl u
1.112 jmc 134: .Op Fl s Ar ca_public
135: .Op Fl z Ar version_number
1.111 djm 136: .Ar
137: .Nm ssh-keygen
138: .Fl Q
139: .Fl f Ar krl_file
140: .Ar
1.163 djm 141: .Nm ssh-keygen
1.171 jmc 142: .Fl Y Cm check-novalidate
143: .Fl n Ar namespace
144: .Fl s Ar signature_file
145: .Nm ssh-keygen
1.163 djm 146: .Fl Y Cm sign
147: .Fl f Ar key_file
148: .Fl n Ar namespace
149: .Ar
150: .Nm ssh-keygen
151: .Fl Y Cm verify
1.171 jmc 152: .Fl f Ar allowed_signers_file
1.163 djm 153: .Fl I Ar signer_identity
154: .Fl n Ar namespace
155: .Fl s Ar signature_file
156: .Op Fl r Ar revocation_file
1.13 aaron 157: .Sh DESCRIPTION
1.2 deraadt 158: .Nm
1.37 markus 159: generates, manages and converts authentication keys for
1.2 deraadt 160: .Xr ssh 1 .
1.15 deraadt 161: .Nm
1.140 jmc 162: can create keys for use by SSH protocol version 2.
1.130 jmc 163: .Pp
1.58 jmc 164: The type of key to be generated is specified with the
1.25 markus 165: .Fl t
1.52 djm 166: option.
1.70 djm 167: If invoked without any arguments,
168: .Nm
1.141 naddy 169: will generate an RSA key.
1.15 deraadt 170: .Pp
1.60 djm 171: .Nm
172: is also used to generate groups for use in Diffie-Hellman group
173: exchange (DH-GEX).
174: See the
175: .Sx MODULI GENERATION
176: section for details.
177: .Pp
1.111 djm 178: Finally,
179: .Nm
180: can be used to generate and update Key Revocation Lists, and to test whether
1.112 jmc 181: given keys have been revoked by one.
182: See the
1.111 djm 183: .Sx KEY REVOCATION LISTS
184: section for details.
185: .Pp
1.2 deraadt 186: Normally each user wishing to use SSH
1.99 djm 187: with public key authentication runs this once to create the authentication
1.1 deraadt 188: key in
1.118 naddy 189: .Pa ~/.ssh/id_dsa ,
1.99 djm 190: .Pa ~/.ssh/id_ecdsa ,
1.118 naddy 191: .Pa ~/.ssh/id_ed25519
1.15 deraadt 192: or
1.68 djm 193: .Pa ~/.ssh/id_rsa .
1.15 deraadt 194: Additionally, the system administrator may use this to generate host keys,
195: as seen in
196: .Pa /etc/rc .
1.2 deraadt 197: .Pp
1.1 deraadt 198: Normally this program generates the key and asks for a file in which
1.12 aaron 199: to store the private key.
200: The public key is stored in a file with the same name but
1.2 deraadt 201: .Dq .pub
1.12 aaron 202: appended.
203: The program also asks for a passphrase.
204: The passphrase may be empty to indicate no passphrase
1.26 markus 205: (host keys must have an empty passphrase), or it may be a string of
1.12 aaron 206: arbitrary length.
1.51 stevesk 207: A passphrase is similar to a password, except it can be a phrase with a
208: series of words, punctuation, numbers, whitespace, or any string of
209: characters you want.
210: Good passphrases are 10-30 characters long, are
1.1 deraadt 211: not simple sentences or otherwise easily guessable (English
1.42 markus 212: prose has only 1-2 bits of entropy per character, and provides very bad
1.51 stevesk 213: passphrases), and contain a mix of upper and lowercase letters,
214: numbers, and non-alphanumeric characters.
1.12 aaron 215: The passphrase can be changed later by using the
1.2 deraadt 216: .Fl p
1.1 deraadt 217: option.
1.2 deraadt 218: .Pp
1.12 aaron 219: There is no way to recover a lost passphrase.
1.105 djm 220: If the passphrase is lost or forgotten, a new key must be generated
221: and the corresponding public key copied to other machines.
1.2 deraadt 222: .Pp
1.153 djm 223: .Nm
224: will by default write keys in an OpenSSH-specific format.
225: This format is preferred as it offers better protection for
226: keys at rest as well as allowing storage of key comments within
227: the private key file itself.
228: The key comment may be useful to help identify the key.
1.12 aaron 229: The comment is initialized to
1.2 deraadt 230: .Dq user@host
231: when the key is created, but can be changed using the
232: .Fl c
1.1 deraadt 233: option.
1.153 djm 234: .Pp
235: It is still possible for
236: .Nm
237: to write the previously-used PEM format private keys using the
238: .Fl m
239: flag.
240: This may be used when generating new keys, and existing new-format
241: keys may be converted using this option in conjunction with the
242: .Fl p
243: (change passphrase) flag.
1.2 deraadt 244: .Pp
1.15 deraadt 245: After a key is generated, instructions below detail where the keys
246: should be placed to be activated.
247: .Pp
1.2 deraadt 248: The options are as follows:
249: .Bl -tag -width Ds
1.102 stevesk 250: .It Fl A
1.139 jmc 251: For each of the key types (rsa, dsa, ecdsa and ed25519)
1.118 naddy 252: for which host keys
1.102 stevesk 253: do not exist, generate the host keys with the default key file path,
254: an empty passphrase, default bits for the key type, and default comment.
1.144 jmc 255: If
1.143 djm 256: .Fl f
1.144 jmc 257: has also been specified, its argument is used as a prefix to the
1.143 djm 258: default path for the resulting host key files.
1.104 jmc 259: This is used by
1.102 stevesk 260: .Pa /etc/rc
261: to generate new host keys.
1.117 djm 262: .It Fl a Ar rounds
1.169 jmc 263: When saving a private key, this option specifies the number of KDF
1.148 djm 264: (key derivation function) rounds used.
1.117 djm 265: Higher numbers result in slower passphrase verification and increased
266: resistance to brute-force password cracking (should the keys be stolen).
267: .Pp
1.140 jmc 268: When screening DH-GEX candidates (using the
1.60 djm 269: .Fl T
1.169 jmc 270: command),
271: this option specifies the number of primality tests to perform.
1.66 jmc 272: .It Fl B
273: Show the bubblebabble digest of specified private or public key file.
1.2 deraadt 274: .It Fl b Ar bits
1.12 aaron 275: Specifies the number of bits in the key to create.
1.158 dtucker 276: For RSA keys, the minimum size is 1024 bits and the default is 3072 bits.
277: Generally, 3072 bits is considered sufficient.
1.72 dtucker 278: DSA keys must be exactly 1024 bits as specified by FIPS 186-2.
1.106 djm 279: For ECDSA keys, the
280: .Fl b
1.107 deraadt 281: flag determines the key length by selecting from one of three elliptic
1.106 djm 282: curve sizes: 256, 384 or 521 bits.
283: Attempting to use bit lengths other than these three values for ECDSA keys
284: will fail.
1.123 sobrado 285: Ed25519 keys have a fixed length and the
1.118 naddy 286: .Fl b
287: flag will be ignored.
1.66 jmc 288: .It Fl C Ar comment
289: Provides a new comment.
1.2 deraadt 290: .It Fl c
1.1 deraadt 291: Requests changing the comment in the private and public key files.
292: The program will prompt for the file containing the private keys, for
1.41 stevesk 293: the passphrase if the key has one, and for the new comment.
1.81 markus 294: .It Fl D Ar pkcs11
1.157 naddy 295: Download the public keys provided by the PKCS#11 shared library
1.83 markus 296: .Ar pkcs11 .
1.98 djm 297: When used in combination with
298: .Fl s ,
299: this option indicates that a CA key resides in a PKCS#11 token (see the
300: .Sx CERTIFICATES
301: section for details).
1.124 djm 302: .It Fl E Ar fingerprint_hash
303: Specifies the hash algorithm used when displaying key fingerprints.
304: Valid options are:
305: .Dq md5
306: and
307: .Dq sha256 .
308: The default is
309: .Dq sha256 .
1.37 markus 310: .It Fl e
1.40 markus 311: This option will read a private or public OpenSSH key file and
1.154 djm 312: print to stdout a public key in one of the formats specified by the
1.95 djm 313: .Fl m
314: option.
315: The default export format is
316: .Dq RFC4716 .
1.96 jmc 317: This option allows exporting OpenSSH keys for use by other programs, including
1.95 djm 318: several commercial SSH implementations.
1.151 djm 319: .It Fl F Ar hostname | [hostname]:port
1.66 jmc 320: Search for the specified
321: .Ar hostname
1.151 djm 322: (with optional port number)
1.66 jmc 323: in a
324: .Pa known_hosts
325: file, listing any occurrences found.
326: This option is useful to find hashed host names or addresses and may also be
327: used in conjunction with the
328: .Fl H
329: option to print found keys in a hashed format.
330: .It Fl f Ar filename
331: Specifies the filename of the key file.
332: .It Fl G Ar output_file
333: Generate candidate primes for DH-GEX.
334: These primes must be screened for
335: safety (using the
336: .Fl T
337: option) before use.
1.57 jakob 338: .It Fl g
1.62 jakob 339: Use generic DNS format when printing fingerprint resource records using the
1.63 jmc 340: .Fl r
1.62 jakob 341: command.
1.66 jmc 342: .It Fl H
343: Hash a
344: .Pa known_hosts
1.67 dtucker 345: file.
346: This replaces all hostnames and addresses with hashed representations
347: within the specified file; the original content is moved to a file with
348: a .old suffix.
1.66 jmc 349: These hashes may be used normally by
350: .Nm ssh
351: and
352: .Nm sshd ,
353: but they do not reveal identifying information should the file's contents
354: be disclosed.
355: This option will not modify existing hashed hostnames and is therefore safe
356: to use on files that mix hashed and non-hashed names.
1.84 djm 357: .It Fl h
358: When signing a key, create a host certificate instead of a user
359: certificate.
360: Please see the
361: .Sx CERTIFICATES
362: section for details.
1.85 jmc 363: .It Fl I Ar certificate_identity
1.84 djm 364: Specify the key identity when signing a public key.
365: Please see the
366: .Sx CERTIFICATES
367: section for details.
1.37 markus 368: .It Fl i
369: This option will read an unencrypted private (or public) key file
1.95 djm 370: in the format specified by the
371: .Fl m
372: option and print an OpenSSH compatible private
1.37 markus 373: (or public) key to stdout.
1.122 jmc 374: This option allows importing keys from other software, including several
375: commercial SSH implementations.
376: The default import format is
377: .Dq RFC4716 .
1.109 dtucker 378: .It Fl J Ar num_lines
379: Exit after screening the specified number of lines
380: while performing DH candidate screening using the
381: .Fl T
382: option.
383: .It Fl j Ar start_line
384: Start screening at the specified line number
385: while performing DH candidate screening using the
386: .Fl T
387: option.
1.108 dtucker 388: .It Fl K Ar checkpt
389: Write the last line processed to the file
390: .Ar checkpt
391: while performing DH candidate screening using the
392: .Fl T
393: option.
394: This will be used to skip lines in the input file that have already been
395: processed if the job is restarted.
1.111 djm 396: .It Fl k
397: Generate a KRL file.
398: In this mode,
399: .Nm
400: will generate a KRL file at the location specified via the
401: .Fl f
1.114 jmc 402: flag that revokes every key or certificate presented on the command line.
1.111 djm 403: Keys/certificates to be revoked may be specified by public key file or
404: using the format described in the
405: .Sx KEY REVOCATION LISTS
406: section.
1.86 djm 407: .It Fl L
1.129 djm 408: Prints the contents of one or more certificates.
1.9 markus 409: .It Fl l
1.77 grunk 410: Show fingerprint of specified public key file.
1.50 markus 411: For RSA and DSA keys
412: .Nm
1.78 jmc 413: tries to find the matching public key file and prints its fingerprint.
414: If combined with
415: .Fl v ,
1.132 jmc 416: a visual ASCII art representation of the key is supplied with the
1.131 djm 417: fingerprint.
1.96 jmc 418: .It Fl M Ar memory
419: Specify the amount of memory to use (in megabytes) when generating
420: candidate moduli for DH-GEX.
1.95 djm 421: .It Fl m Ar key_format
1.155 djm 422: Specify a key format for key generation, the
1.95 djm 423: .Fl i
1.155 djm 424: (import),
1.95 djm 425: .Fl e
1.155 djm 426: (export) conversion options, and the
427: .Fl p
428: change passphrase operation.
429: The latter may be used to convert between OpenSSH private key and PEM
430: private key formats.
1.95 djm 431: The supported key formats are:
432: .Dq RFC4716
1.96 jmc 433: (RFC 4716/SSH2 public or private key),
1.95 djm 434: .Dq PKCS8
1.161 djm 435: (PKCS8 public or private key)
1.95 djm 436: or
437: .Dq PEM
438: (PEM public key).
1.161 djm 439: By default OpenSSH will write newly-generated private keys in its own
440: format, but when converting public keys for export the default format is
1.95 djm 441: .Dq RFC4716 .
1.148 djm 442: Setting a format of
443: .Dq PEM
444: when generating or updating a supported private key type will cause the
445: key to be stored in the legacy PEM private key format.
1.66 jmc 446: .It Fl N Ar new_passphrase
447: Provides the new passphrase.
1.84 djm 448: .It Fl n Ar principals
449: Specify one or more principals (user or host names) to be included in
450: a certificate when signing a key.
451: Multiple principals may be specified, separated by commas.
452: Please see the
453: .Sx CERTIFICATES
454: section for details.
1.93 djm 455: .It Fl O Ar option
456: Specify a certificate option when signing a key.
1.84 djm 457: This option may be specified multiple times.
1.137 jmc 458: See also the
1.84 djm 459: .Sx CERTIFICATES
1.137 jmc 460: section for further details.
1.146 djm 461: .Pp
462: At present, no standard options are valid for host keys.
1.93 djm 463: The options that are valid for user certificates are:
1.137 jmc 464: .Pp
465: .Bl -tag -width Ds -compact
1.89 jmc 466: .It Ic clear
467: Clear all enabled permissions.
468: This is useful for clearing the default set of permissions so permissions may
469: be added individually.
1.137 jmc 470: .Pp
471: .It Ic critical : Ns Ar name Ns Op Ns = Ns Ar contents
472: .It Ic extension : Ns Ar name Ns Op Ns = Ns Ar contents
473: Includes an arbitrary certificate critical option or extension.
474: The specified
475: .Ar name
476: should include a domain suffix, e.g.\&
477: .Dq name@example.com .
478: If
479: .Ar contents
480: is specified then it is included as the contents of the extension/option
481: encoded as a string, otherwise the extension/option is created with no
482: contents (usually indicating a flag).
483: Extensions may be ignored by a client or server that does not recognise them,
484: whereas unknown critical options will cause the certificate to be refused.
1.138 jmc 485: .Pp
1.89 jmc 486: .It Ic force-command Ns = Ns Ar command
487: Forces the execution of
488: .Ar command
489: instead of any shell or command specified by the user when
490: the certificate is used for authentication.
1.137 jmc 491: .Pp
1.84 djm 492: .It Ic no-agent-forwarding
493: Disable
494: .Xr ssh-agent 1
1.85 jmc 495: forwarding (permitted by default).
1.137 jmc 496: .Pp
1.84 djm 497: .It Ic no-port-forwarding
1.85 jmc 498: Disable port forwarding (permitted by default).
1.137 jmc 499: .Pp
1.84 djm 500: .It Ic no-pty
1.85 jmc 501: Disable PTY allocation (permitted by default).
1.137 jmc 502: .Pp
1.84 djm 503: .It Ic no-user-rc
504: Disable execution of
505: .Pa ~/.ssh/rc
506: by
1.85 jmc 507: .Xr sshd 8
508: (permitted by default).
1.137 jmc 509: .Pp
1.89 jmc 510: .It Ic no-x11-forwarding
511: Disable X11 forwarding (permitted by default).
1.137 jmc 512: .Pp
1.88 djm 513: .It Ic permit-agent-forwarding
514: Allows
515: .Xr ssh-agent 1
516: forwarding.
1.137 jmc 517: .Pp
1.84 djm 518: .It Ic permit-port-forwarding
519: Allows port forwarding.
1.137 jmc 520: .Pp
1.84 djm 521: .It Ic permit-pty
522: Allows PTY allocation.
1.137 jmc 523: .Pp
1.84 djm 524: .It Ic permit-user-rc
525: Allows execution of
526: .Pa ~/.ssh/rc
527: by
528: .Xr sshd 8 .
1.137 jmc 529: .Pp
1.146 djm 530: .It Ic permit-X11-forwarding
1.89 jmc 531: Allows X11 forwarding.
1.137 jmc 532: .Pp
1.89 jmc 533: .It Ic source-address Ns = Ns Ar address_list
1.90 jmc 534: Restrict the source addresses from which the certificate is considered valid.
1.84 djm 535: The
536: .Ar address_list
537: is a comma-separated list of one or more address/netmask pairs in CIDR
538: format.
539: .El
1.66 jmc 540: .It Fl P Ar passphrase
541: Provides the (old) passphrase.
1.2 deraadt 542: .It Fl p
1.1 deraadt 543: Requests changing the passphrase of a private key file instead of
1.12 aaron 544: creating a new private key.
545: The program will prompt for the file
1.1 deraadt 546: containing the private key, for the old passphrase, and twice for the
547: new passphrase.
1.113 jmc 548: .It Fl Q
549: Test whether keys have been revoked in a KRL.
1.5 aaron 550: .It Fl q
551: Silence
552: .Nm ssh-keygen .
1.152 djm 553: .It Fl R Ar hostname | [hostname]:port
1.151 djm 554: Removes all keys belonging to the specified
1.64 djm 555: .Ar hostname
1.151 djm 556: (with optional port number)
1.65 jmc 557: from a
1.64 djm 558: .Pa known_hosts
559: file.
1.65 jmc 560: This option is useful to delete hashed hosts (see the
1.64 djm 561: .Fl H
562: option above).
1.66 jmc 563: .It Fl r Ar hostname
564: Print the SSHFP fingerprint resource record named
565: .Ar hostname
566: for the specified public key file.
1.60 djm 567: .It Fl S Ar start
568: Specify start point (in hex) when generating candidate moduli for DH-GEX.
1.84 djm 569: .It Fl s Ar ca_key
570: Certify (sign) a public key using the specified CA key.
571: Please see the
572: .Sx CERTIFICATES
573: section for details.
1.111 djm 574: .Pp
575: When generating a KRL,
576: .Fl s
1.112 jmc 577: specifies a path to a CA public key file used to revoke certificates directly
1.111 djm 578: by key ID or serial number.
579: See the
580: .Sx KEY REVOCATION LISTS
581: section for details.
1.60 djm 582: .It Fl T Ar output_file
583: Test DH group exchange candidate primes (generated using the
584: .Fl G
585: option) for safety.
1.139 jmc 586: .It Fl t Cm dsa | ecdsa | ed25519 | rsa
1.66 jmc 587: Specifies the type of key to create.
588: The possible values are
1.100 naddy 589: .Dq dsa ,
1.118 naddy 590: .Dq ecdsa ,
591: .Dq ed25519 ,
1.100 naddy 592: or
1.139 jmc 593: .Dq rsa .
1.159 djm 594: .Pp
595: This flag may also be used to specify the desired signature type when
1.160 jmc 596: signing certificates using an RSA CA key.
1.159 djm 597: The available RSA signature variants are
598: .Dq ssh-rsa
599: (SHA1 signatures, not recommended),
1.160 jmc 600: .Dq rsa-sha2-256 ,
601: and
1.159 djm 602: .Dq rsa-sha2-512
603: (the default).
1.142 djm 604: .It Fl U
605: When used in combination with
606: .Fl s ,
607: this option indicates that a CA key resides in a
608: .Xr ssh-agent 1 .
609: See the
610: .Sx CERTIFICATES
611: section for more information.
1.112 jmc 612: .It Fl u
613: Update a KRL.
614: When specified with
615: .Fl k ,
1.114 jmc 616: keys listed via the command line are added to the existing KRL rather than
1.112 jmc 617: a new KRL being created.
1.84 djm 618: .It Fl V Ar validity_interval
619: Specify a validity interval when signing a certificate.
620: A validity interval may consist of a single time, indicating that the
621: certificate is valid beginning now and expiring at that time, or may consist
622: of two times separated by a colon to indicate an explicit time interval.
1.145 djm 623: .Pp
624: The start time may be specified as the string
625: .Dq always
626: to indicate the certificate has no specified start time,
1.147 djm 627: a date in YYYYMMDD format, a time in YYYYMMDDHHMM[SS] format,
1.145 djm 628: a relative time (to the current time) consisting of a minus sign followed by
629: an interval in the format described in the
1.116 jmc 630: TIME FORMATS section of
1.90 jmc 631: .Xr sshd_config 5 .
1.145 djm 632: .Pp
1.147 djm 633: The end time may be specified as a YYYYMMDD date, a YYYYMMDDHHMM[SS] time,
1.145 djm 634: a relative time starting with a plus character or the string
635: .Dq forever
636: to indicate that the certificate has no expirty date.
1.84 djm 637: .Pp
638: For example:
639: .Dq +52w1d
640: (valid from now to 52 weeks and one day from now),
641: .Dq -4w:+4w
642: (valid from four weeks ago to four weeks from now),
643: .Dq 20100101123000:20110101123000
644: (valid from 12:30 PM, January 1st, 2010 to 12:30 PM, January 1st, 2011),
645: .Dq -1d:20110101
646: (valid from yesterday to midnight, January 1st, 2011).
1.145 djm 647: .Dq -1m:forever
648: (valid from one minute ago and never expiring).
1.61 djm 649: .It Fl v
650: Verbose mode.
651: Causes
652: .Nm
653: to print debugging messages about its progress.
654: This is helpful for debugging moduli generation.
655: Multiple
656: .Fl v
657: options increase the verbosity.
658: The maximum is 3.
1.66 jmc 659: .It Fl W Ar generator
660: Specify desired generator when testing candidate moduli for DH-GEX.
661: .It Fl y
662: This option will read a private
663: OpenSSH format file and print an OpenSSH public key to stdout.
1.166 jmc 664: .It Fl Y Cm sign
1.163 djm 665: Cryptographically sign a file or some data using a SSH key.
666: When signing,
667: .Nm
668: accepts zero or more files to sign on the command-line - if no files
669: are specified then
670: .Nm
671: will sign data presented on standard input.
672: Signatures are written to the path of the input file with
673: .Dq .sig
674: appended, or to standard output if the message to be signed was read from
675: standard input.
676: .Pp
677: The key used for signing is specified using the
678: .Fl f
679: option and may refer to either a private key, or a public key with the private
680: half available via
681: .Xr ssh-agent 1 .
682: An additional signature namespace, used to prevent signature confusion across
683: different domains of use (e.g. file signing vs email signing) must be provided
684: via the
685: .Fl n
686: flag.
687: Namespaces are arbitrary strings, and may include:
688: .Dq file
689: for file signing,
690: .Dq email
691: for email signing.
692: For custom uses, it is recommended to use names following a
693: NAMESPACE@YOUR.DOMAIN pattern to generate unambiguous namespaces.
1.166 jmc 694: .It Fl Y Cm verify
1.163 djm 695: Request to verify a signature generated using
696: .Nm
1.166 jmc 697: .Fl Y Cm sign
1.163 djm 698: as described above.
699: When verifying a signature,
700: .Nm
701: accepts a message on standard input and a signature namespace using
702: .Fl n .
703: A file containing the corresponding signature must also be supplied using the
704: .Fl s
705: flag, along with the identity of the signer using
706: .Fl I
707: and a list of allowed signers via the
708: .Fl f
709: flag.
710: The format of the allowed signers file is documented in the
711: .Sx ALLOWED SIGNERS
712: section below.
713: A file containing revoked keys can be passed using the
714: .Fl r
1.165 jmc 715: flag.
716: The revocation file may be a KRL or a one-per-line list of public keys.
1.163 djm 717: Successful verification by an authorized signer is signalled by
1.167 djm 718: .Nm
1.172 ! jmc 719: returning a zero exit status.
1.167 djm 720: .It Fl Y Cm check-novalidate
721: Checks that a signature generated using
722: .Nm
723: .Fl Y Cm sign
724: has a valid structure.
725: This does not validate if a signature comes from an authorized signer.
726: When testing a signature,
727: .Nm
728: accepts a message on standard input and a signature namespace using
729: .Fl n .
730: A file containing the corresponding signature must also be supplied using the
731: .Fl s
1.168 jmc 732: flag.
733: Successful testing of the signature is signalled by
1.163 djm 734: .Nm
735: returning a zero exit status.
1.93 djm 736: .It Fl z Ar serial_number
737: Specifies a serial number to be embedded in the certificate to distinguish
738: this certificate from others from the same CA.
1.156 djm 739: If the
740: .Ar serial_number
741: is prefixed with a
742: .Sq +
743: character, then the serial number will be incremented for each certificate
744: signed on a single command-line.
1.93 djm 745: The default serial number is zero.
1.111 djm 746: .Pp
747: When generating a KRL, the
748: .Fl z
749: flag is used to specify a KRL version number.
1.2 deraadt 750: .El
1.60 djm 751: .Sh MODULI GENERATION
752: .Nm
753: may be used to generate groups for the Diffie-Hellman Group Exchange
754: (DH-GEX) protocol.
755: Generating these groups is a two-step process: first, candidate
756: primes are generated using a fast, but memory intensive process.
757: These candidate primes are then tested for suitability (a CPU-intensive
758: process).
759: .Pp
760: Generation of primes is performed using the
761: .Fl G
762: option.
763: The desired length of the primes may be specified by the
764: .Fl b
765: option.
766: For example:
767: .Pp
1.66 jmc 768: .Dl # ssh-keygen -G moduli-2048.candidates -b 2048
1.60 djm 769: .Pp
770: By default, the search for primes begins at a random point in the
771: desired length range.
772: This may be overridden using the
773: .Fl S
774: option, which specifies a different start point (in hex).
775: .Pp
1.109 dtucker 776: Once a set of candidates have been generated, they must be screened for
1.60 djm 777: suitability.
778: This may be performed using the
779: .Fl T
780: option.
781: In this mode
782: .Nm
783: will read candidates from standard input (or a file specified using the
784: .Fl f
785: option).
786: For example:
787: .Pp
1.66 jmc 788: .Dl # ssh-keygen -T moduli-2048 -f moduli-2048.candidates
1.60 djm 789: .Pp
790: By default, each candidate will be subjected to 100 primality tests.
791: This may be overridden using the
792: .Fl a
793: option.
794: The DH generator value will be chosen automatically for the
795: prime under consideration.
796: If a specific generator is desired, it may be requested using the
797: .Fl W
798: option.
1.66 jmc 799: Valid generator values are 2, 3, and 5.
1.60 djm 800: .Pp
801: Screened DH groups may be installed in
802: .Pa /etc/moduli .
803: It is important that this file contains moduli of a range of bit lengths and
804: that both ends of a connection share common moduli.
1.84 djm 805: .Sh CERTIFICATES
806: .Nm
807: supports signing of keys to produce certificates that may be used for
808: user or host authentication.
809: Certificates consist of a public key, some identity information, zero or
1.94 jmc 810: more principal (user or host) names and a set of options that
1.84 djm 811: are signed by a Certification Authority (CA) key.
812: Clients or servers may then trust only the CA key and verify its signature
813: on a certificate rather than trusting many user/host keys.
814: Note that OpenSSH certificates are a different, and much simpler, format to
815: the X.509 certificates used in
816: .Xr ssl 8 .
817: .Pp
818: .Nm
819: supports two types of certificates: user and host.
820: User certificates authenticate users to servers, whereas host certificates
1.85 jmc 821: authenticate server hosts to users.
822: To generate a user certificate:
1.84 djm 823: .Pp
824: .Dl $ ssh-keygen -s /path/to/ca_key -I key_id /path/to/user_key.pub
825: .Pp
826: The resultant certificate will be placed in
1.91 djm 827: .Pa /path/to/user_key-cert.pub .
1.84 djm 828: A host certificate requires the
829: .Fl h
830: option:
831: .Pp
832: .Dl $ ssh-keygen -s /path/to/ca_key -I key_id -h /path/to/host_key.pub
833: .Pp
834: The host certificate will be output to
1.91 djm 835: .Pa /path/to/host_key-cert.pub .
1.98 djm 836: .Pp
837: It is possible to sign using a CA key stored in a PKCS#11 token by
838: providing the token library using
839: .Fl D
840: and identifying the CA key by providing its public half as an argument
841: to
842: .Fl s :
843: .Pp
1.127 naddy 844: .Dl $ ssh-keygen -s ca_key.pub -D libpkcs11.so -I key_id user_key.pub
1.142 djm 845: .Pp
846: Similarly, it is possible for the CA key to be hosted in a
847: .Xr ssh-agent 1 .
848: This is indicated by the
849: .Fl U
850: flag and, again, the CA key must be identified by its public half.
851: .Pp
852: .Dl $ ssh-keygen -Us ca_key.pub -I key_id user_key.pub
1.98 djm 853: .Pp
854: In all cases,
1.84 djm 855: .Ar key_id
856: is a "key identifier" that is logged by the server when the certificate
857: is used for authentication.
858: .Pp
859: Certificates may be limited to be valid for a set of principal (user/host)
860: names.
861: By default, generated certificates are valid for all users or hosts.
862: To generate a certificate for a specified set of principals:
863: .Pp
864: .Dl $ ssh-keygen -s ca_key -I key_id -n user1,user2 user_key.pub
1.127 naddy 865: .Dl "$ ssh-keygen -s ca_key -I key_id -h -n host.domain host_key.pub"
1.84 djm 866: .Pp
867: Additional limitations on the validity and use of user certificates may
1.94 jmc 868: be specified through certificate options.
1.93 djm 869: A certificate option may disable features of the SSH session, may be
1.84 djm 870: valid only when presented from particular source addresses or may
871: force the use of a specific command.
1.93 djm 872: For a list of valid certificate options, see the documentation for the
1.84 djm 873: .Fl O
874: option above.
875: .Pp
876: Finally, certificates may be defined with a validity lifetime.
877: The
878: .Fl V
879: option allows specification of certificate start and end times.
880: A certificate that is presented at a time outside this range will not be
881: considered valid.
1.110 jmc 882: By default, certificates are valid from
883: .Ux
884: Epoch to the distant future.
1.84 djm 885: .Pp
886: For certificates to be used for user or host authentication, the CA
887: public key must be trusted by
888: .Xr sshd 8
889: or
890: .Xr ssh 1 .
891: Please refer to those manual pages for details.
1.111 djm 892: .Sh KEY REVOCATION LISTS
893: .Nm
894: is able to manage OpenSSH format Key Revocation Lists (KRLs).
895: These binary files specify keys or certificates to be revoked using a
1.119 tedu 896: compact format, taking as little as one bit per certificate if they are being
1.111 djm 897: revoked by serial number.
898: .Pp
899: KRLs may be generated using the
900: .Fl k
901: flag.
1.114 jmc 902: This option reads one or more files from the command line and generates a new
1.111 djm 903: KRL.
904: The files may either contain a KRL specification (see below) or public keys,
905: listed one per line.
906: Plain public keys are revoked by listing their hash or contents in the KRL and
907: certificates revoked by serial number or key ID (if the serial is zero or
908: not available).
909: .Pp
910: Revoking keys using a KRL specification offers explicit control over the
911: types of record used to revoke keys and may be used to directly revoke
912: certificates by serial number or key ID without having the complete original
913: certificate on hand.
914: A KRL specification consists of lines containing one of the following directives
915: followed by a colon and some directive-specific information.
916: .Bl -tag -width Ds
1.115 jmc 917: .It Cm serial : Ar serial_number Ns Op - Ns Ar serial_number
1.111 djm 918: Revokes a certificate with the specified serial number.
1.112 jmc 919: Serial numbers are 64-bit values, not including zero and may be expressed
1.111 djm 920: in decimal, hex or octal.
921: If two serial numbers are specified separated by a hyphen, then the range
922: of serial numbers including and between each is revoked.
923: The CA key must have been specified on the
924: .Nm
1.114 jmc 925: command line using the
1.111 djm 926: .Fl s
927: option.
928: .It Cm id : Ar key_id
929: Revokes a certificate with the specified key ID string.
930: The CA key must have been specified on the
931: .Nm
1.114 jmc 932: command line using the
1.111 djm 933: .Fl s
934: option.
935: .It Cm key : Ar public_key
936: Revokes the specified key.
1.112 jmc 937: If a certificate is listed, then it is revoked as a plain public key.
1.111 djm 938: .It Cm sha1 : Ar public_key
1.149 djm 939: Revokes the specified key by including its SHA1 hash in the KRL.
940: .It Cm sha256 : Ar public_key
941: Revokes the specified key by including its SHA256 hash in the KRL.
942: KRLs that revoke keys by SHA256 hash are not supported by OpenSSH versions
943: prior to 7.9.
944: .It Cm hash : Ar fingerprint
1.150 djm 945: Revokes a key using a fingerprint hash, as obtained from a
1.149 djm 946: .Xr sshd 8
947: authentication log message or the
948: .Nm
949: .Fl l
950: flag.
951: Only SHA256 fingerprints are supported here and resultant KRLs are
952: not supported by OpenSSH versions prior to 7.9.
1.111 djm 953: .El
954: .Pp
955: KRLs may be updated using the
956: .Fl u
957: flag in addition to
958: .Fl k .
1.114 jmc 959: When this option is specified, keys listed via the command line are merged into
1.111 djm 960: the KRL, adding to those already there.
961: .Pp
962: It is also possible, given a KRL, to test whether it revokes a particular key
963: (or keys).
964: The
965: .Fl Q
1.128 jmc 966: flag will query an existing KRL, testing each key specified on the command line.
1.114 jmc 967: If any key listed on the command line has been revoked (or an error encountered)
1.111 djm 968: then
969: .Nm
970: will exit with a non-zero exit status.
971: A zero exit status will only be returned if no key was revoked.
1.163 djm 972: .Sh ALLOWED SIGNERS
973: When verifying signatures,
974: .Nm
975: uses a simple list of identities and keys to determine whether a signature
976: comes from an authorized source.
977: This "allowed signers" file uses a format patterned after the
978: AUTHORIZED_KEYS FILE FORMAT described in
1.165 jmc 979: .Xr sshd 8 .
1.163 djm 980: Each line of the file contains the following space-separated fields:
981: principals, options, keytype, base64-encoded key.
982: Empty lines and lines starting with a
983: .Ql #
984: are ignored as comments.
985: .Pp
986: The principals field is a pattern-list (See PATTERNS in
987: .Xr ssh_config 5 )
988: consisting of one or more comma-separated USER@DOMAIN identity patterns
989: that are accepted for signing.
990: When verifying, the identity presented via the
1.172 ! jmc 991: .Fl I
! 992: option must match a principals pattern in order for the corresponding key to be
1.163 djm 993: considered acceptable for verification.
994: .Pp
995: The options (if present) consist of comma-separated option specifications.
996: No spaces are permitted, except within double quotes.
997: The following option specifications are supported (note that option keywords
998: are case-insensitive):
999: .Bl -tag -width Ds
1000: .It Cm cert-authority
1001: Indicates that this key is accepted as a certificate authority (CA) and
1002: that certificates signed by this CA may be accepted for verification.
1003: .It Cm namespaces="namespace-list"
1004: Specifies a pattern-list of namespaces that are accepted for this key.
1.164 djm 1005: If this option is present, the signature namespace embedded in the
1.163 djm 1006: signature object and presented on the verification command-line must
1007: match the specified list before the key will be considered acceptable.
1008: .El
1009: .Pp
1010: When verifying signatures made by certificates, the expected principal
1011: name must match both the principals pattern in the allowed signers file and
1012: the principals embedded in the certificate itself.
1013: .Pp
1014: An example allowed signers file:
1015: .Bd -literal -offset 3n
1016: # Comments allowed at start of line
1017: user1@example.com,user2@example.com ssh-rsa AAAAX1...
1018: # A certificate authority, trusted for all principals in a domain.
1019: *@example.com cert-authority ssh-ed25519 AAAB4...
1020: # A key that is accepted only for file signing.
1021: user2@example.com namespaces="file" ssh-ed25519 AAA41...
1022: .Ed
1.2 deraadt 1023: .Sh FILES
1.100 naddy 1024: .Bl -tag -width Ds -compact
1.68 djm 1025: .It Pa ~/.ssh/id_dsa
1.100 naddy 1026: .It Pa ~/.ssh/id_ecdsa
1.118 naddy 1027: .It Pa ~/.ssh/id_ed25519
1.100 naddy 1028: .It Pa ~/.ssh/id_rsa
1.141 naddy 1029: Contains the DSA, ECDSA, Ed25519 or RSA
1.118 naddy 1030: authentication identity of the user.
1.15 deraadt 1031: This file should not be readable by anyone but the user.
1032: It is possible to
1033: specify a passphrase when generating the key; that passphrase will be
1.80 dtucker 1034: used to encrypt the private part of this file using 128-bit AES.
1.15 deraadt 1035: This file is not automatically accessed by
1036: .Nm
1037: but it is offered as the default file for the private key.
1.46 markus 1038: .Xr ssh 1
1.15 deraadt 1039: will read this file when a login attempt is made.
1.100 naddy 1040: .Pp
1.68 djm 1041: .It Pa ~/.ssh/id_dsa.pub
1.100 naddy 1042: .It Pa ~/.ssh/id_ecdsa.pub
1.118 naddy 1043: .It Pa ~/.ssh/id_ed25519.pub
1.68 djm 1044: .It Pa ~/.ssh/id_rsa.pub
1.141 naddy 1045: Contains the DSA, ECDSA, Ed25519 or RSA
1.118 naddy 1046: public key for authentication.
1.15 deraadt 1047: The contents of this file should be added to
1.68 djm 1048: .Pa ~/.ssh/authorized_keys
1.15 deraadt 1049: on all machines
1.49 deraadt 1050: where the user wishes to log in using public key authentication.
1.12 aaron 1051: There is no need to keep the contents of this file secret.
1.100 naddy 1052: .Pp
1.60 djm 1053: .It Pa /etc/moduli
1054: Contains Diffie-Hellman groups used for DH-GEX.
1055: The file format is described in
1056: .Xr moduli 5 .
1.19 aaron 1057: .El
1.2 deraadt 1058: .Sh SEE ALSO
1059: .Xr ssh 1 ,
1060: .Xr ssh-add 1 ,
1.8 ericj 1061: .Xr ssh-agent 1 ,
1.60 djm 1062: .Xr moduli 5 ,
1.30 itojun 1063: .Xr sshd 8
1.37 markus 1064: .Rs
1.73 markus 1065: .%R RFC 4716
1066: .%T "The Secure Shell (SSH) Public Key File Format"
1067: .%D 2006
1.37 markus 1068: .Re
1.59 jmc 1069: .Sh AUTHORS
1070: OpenSSH is a derivative of the original and free
1071: ssh 1.2.12 release by Tatu Ylonen.
1072: Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos,
1073: Theo de Raadt and Dug Song
1074: removed many bugs, re-added newer features and
1075: created OpenSSH.
1076: Markus Friedl contributed the support for SSH
1077: protocol versions 1.5 and 2.0.