Annotation of src/usr.bin/ssh/ssh-keygen.1, Revision 1.166
1.166 ! jmc 1: .\" $OpenBSD: ssh-keygen.1,v 1.165 2019/09/04 05:56:54 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.166 ! jmc 38: .Dd $Mdocdate: September 4 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
1.97 schwarze 45: .Bk -words
1.2 deraadt 46: .Nm ssh-keygen
1.25 markus 47: .Op Fl q
1.2 deraadt 48: .Op Fl b Ar bits
1.139 jmc 49: .Op Fl t Cm dsa | ecdsa | ed25519 | rsa
1.2 deraadt 50: .Op Fl N Ar new_passphrase
51: .Op Fl C Ar comment
1.20 markus 52: .Op Fl f Ar output_keyfile
1.155 djm 53: .Op Fl m Ar format
1.2 deraadt 54: .Nm ssh-keygen
55: .Fl p
56: .Op Fl P Ar old_passphrase
57: .Op Fl N Ar new_passphrase
1.9 markus 58: .Op Fl f Ar keyfile
1.155 djm 59: .Op Fl m Ar format
1.2 deraadt 60: .Nm ssh-keygen
1.37 markus 61: .Fl i
1.95 djm 62: .Op Fl m Ar key_format
1.20 markus 63: .Op Fl f Ar input_keyfile
1.16 deraadt 64: .Nm ssh-keygen
1.37 markus 65: .Fl e
1.95 djm 66: .Op Fl m Ar key_format
1.20 markus 67: .Op Fl f Ar input_keyfile
1.16 deraadt 68: .Nm ssh-keygen
1.17 markus 69: .Fl y
1.20 markus 70: .Op Fl f Ar input_keyfile
1.17 markus 71: .Nm ssh-keygen
1.2 deraadt 72: .Fl c
73: .Op Fl P Ar passphrase
74: .Op Fl C Ar comment
1.9 markus 75: .Op Fl f Ar keyfile
76: .Nm ssh-keygen
77: .Fl l
1.125 naddy 78: .Op Fl v
1.124 djm 79: .Op Fl E Ar fingerprint_hash
1.35 markus 80: .Op Fl f Ar input_keyfile
81: .Nm ssh-keygen
82: .Fl B
1.20 markus 83: .Op Fl f Ar input_keyfile
1.48 jakob 84: .Nm ssh-keygen
1.82 jmc 85: .Fl D Ar pkcs11
1.48 jakob 86: .Nm ssh-keygen
1.64 djm 87: .Fl F Ar hostname
88: .Op Fl f Ar known_hosts_file
1.79 sthen 89: .Op Fl l
1.162 djm 90: .Op Fl v
1.64 djm 91: .Nm ssh-keygen
92: .Fl H
93: .Op Fl f Ar known_hosts_file
94: .Nm ssh-keygen
95: .Fl R Ar hostname
96: .Op Fl f Ar known_hosts_file
1.57 jakob 97: .Nm ssh-keygen
98: .Fl r Ar hostname
99: .Op Fl f Ar input_keyfile
100: .Op Fl g
1.60 djm 101: .Nm ssh-keygen
102: .Fl G Ar output_file
1.61 djm 103: .Op Fl v
1.60 djm 104: .Op Fl b Ar bits
105: .Op Fl M Ar memory
106: .Op Fl S Ar start_point
107: .Nm ssh-keygen
108: .Fl T Ar output_file
109: .Fl f Ar input_file
1.61 djm 110: .Op Fl v
1.117 djm 111: .Op Fl a Ar rounds
1.109 dtucker 112: .Op Fl J Ar num_lines
113: .Op Fl j Ar start_line
1.108 dtucker 114: .Op Fl K Ar checkpt
1.60 djm 115: .Op Fl W Ar generator
1.84 djm 116: .Nm ssh-keygen
117: .Fl s Ar ca_key
118: .Fl I Ar certificate_identity
119: .Op Fl h
1.142 djm 120: .Op Fl U
121: .Op Fl D Ar pkcs11_provider
1.84 djm 122: .Op Fl n Ar principals
1.93 djm 123: .Op Fl O Ar option
1.84 djm 124: .Op Fl V Ar validity_interval
1.93 djm 125: .Op Fl z Ar serial_number
1.84 djm 126: .Ar
1.86 djm 127: .Nm ssh-keygen
128: .Fl L
129: .Op Fl f Ar input_keyfile
1.102 stevesk 130: .Nm ssh-keygen
131: .Fl A
1.143 djm 132: .Op Fl f Ar prefix_path
1.111 djm 133: .Nm ssh-keygen
134: .Fl k
135: .Fl f Ar krl_file
136: .Op Fl u
1.112 jmc 137: .Op Fl s Ar ca_public
138: .Op Fl z Ar version_number
1.111 djm 139: .Ar
140: .Nm ssh-keygen
141: .Fl Q
142: .Fl f Ar krl_file
143: .Ar
1.163 djm 144: .Nm ssh-keygen
145: .Fl Y Cm sign
146: .Fl f Ar key_file
147: .Fl n Ar namespace
148: .Ar
149: .Nm ssh-keygen
150: .Fl Y Cm verify
151: .Fl I Ar signer_identity
152: .Fl f Ar allowed_keys_file
153: .Fl n Ar namespace
154: .Fl s Ar signature_file
155: .Op Fl r Ar revocation_file
1.85 jmc 156: .Ek
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.148 djm 263: When saving a private key this option specifies the number of KDF
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.117 djm 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
718: .Nm
719: returning a zero exit status.
1.93 djm 720: .It Fl z Ar serial_number
721: Specifies a serial number to be embedded in the certificate to distinguish
722: this certificate from others from the same CA.
1.156 djm 723: If the
724: .Ar serial_number
725: is prefixed with a
726: .Sq +
727: character, then the serial number will be incremented for each certificate
728: signed on a single command-line.
1.93 djm 729: The default serial number is zero.
1.111 djm 730: .Pp
731: When generating a KRL, the
732: .Fl z
733: flag is used to specify a KRL version number.
1.2 deraadt 734: .El
1.60 djm 735: .Sh MODULI GENERATION
736: .Nm
737: may be used to generate groups for the Diffie-Hellman Group Exchange
738: (DH-GEX) protocol.
739: Generating these groups is a two-step process: first, candidate
740: primes are generated using a fast, but memory intensive process.
741: These candidate primes are then tested for suitability (a CPU-intensive
742: process).
743: .Pp
744: Generation of primes is performed using the
745: .Fl G
746: option.
747: The desired length of the primes may be specified by the
748: .Fl b
749: option.
750: For example:
751: .Pp
1.66 jmc 752: .Dl # ssh-keygen -G moduli-2048.candidates -b 2048
1.60 djm 753: .Pp
754: By default, the search for primes begins at a random point in the
755: desired length range.
756: This may be overridden using the
757: .Fl S
758: option, which specifies a different start point (in hex).
759: .Pp
1.109 dtucker 760: Once a set of candidates have been generated, they must be screened for
1.60 djm 761: suitability.
762: This may be performed using the
763: .Fl T
764: option.
765: In this mode
766: .Nm
767: will read candidates from standard input (or a file specified using the
768: .Fl f
769: option).
770: For example:
771: .Pp
1.66 jmc 772: .Dl # ssh-keygen -T moduli-2048 -f moduli-2048.candidates
1.60 djm 773: .Pp
774: By default, each candidate will be subjected to 100 primality tests.
775: This may be overridden using the
776: .Fl a
777: option.
778: The DH generator value will be chosen automatically for the
779: prime under consideration.
780: If a specific generator is desired, it may be requested using the
781: .Fl W
782: option.
1.66 jmc 783: Valid generator values are 2, 3, and 5.
1.60 djm 784: .Pp
785: Screened DH groups may be installed in
786: .Pa /etc/moduli .
787: It is important that this file contains moduli of a range of bit lengths and
788: that both ends of a connection share common moduli.
1.84 djm 789: .Sh CERTIFICATES
790: .Nm
791: supports signing of keys to produce certificates that may be used for
792: user or host authentication.
793: Certificates consist of a public key, some identity information, zero or
1.94 jmc 794: more principal (user or host) names and a set of options that
1.84 djm 795: are signed by a Certification Authority (CA) key.
796: Clients or servers may then trust only the CA key and verify its signature
797: on a certificate rather than trusting many user/host keys.
798: Note that OpenSSH certificates are a different, and much simpler, format to
799: the X.509 certificates used in
800: .Xr ssl 8 .
801: .Pp
802: .Nm
803: supports two types of certificates: user and host.
804: User certificates authenticate users to servers, whereas host certificates
1.85 jmc 805: authenticate server hosts to users.
806: To generate a user certificate:
1.84 djm 807: .Pp
808: .Dl $ ssh-keygen -s /path/to/ca_key -I key_id /path/to/user_key.pub
809: .Pp
810: The resultant certificate will be placed in
1.91 djm 811: .Pa /path/to/user_key-cert.pub .
1.84 djm 812: A host certificate requires the
813: .Fl h
814: option:
815: .Pp
816: .Dl $ ssh-keygen -s /path/to/ca_key -I key_id -h /path/to/host_key.pub
817: .Pp
818: The host certificate will be output to
1.91 djm 819: .Pa /path/to/host_key-cert.pub .
1.98 djm 820: .Pp
821: It is possible to sign using a CA key stored in a PKCS#11 token by
822: providing the token library using
823: .Fl D
824: and identifying the CA key by providing its public half as an argument
825: to
826: .Fl s :
827: .Pp
1.127 naddy 828: .Dl $ ssh-keygen -s ca_key.pub -D libpkcs11.so -I key_id user_key.pub
1.142 djm 829: .Pp
830: Similarly, it is possible for the CA key to be hosted in a
831: .Xr ssh-agent 1 .
832: This is indicated by the
833: .Fl U
834: flag and, again, the CA key must be identified by its public half.
835: .Pp
836: .Dl $ ssh-keygen -Us ca_key.pub -I key_id user_key.pub
1.98 djm 837: .Pp
838: In all cases,
1.84 djm 839: .Ar key_id
840: is a "key identifier" that is logged by the server when the certificate
841: is used for authentication.
842: .Pp
843: Certificates may be limited to be valid for a set of principal (user/host)
844: names.
845: By default, generated certificates are valid for all users or hosts.
846: To generate a certificate for a specified set of principals:
847: .Pp
848: .Dl $ ssh-keygen -s ca_key -I key_id -n user1,user2 user_key.pub
1.127 naddy 849: .Dl "$ ssh-keygen -s ca_key -I key_id -h -n host.domain host_key.pub"
1.84 djm 850: .Pp
851: Additional limitations on the validity and use of user certificates may
1.94 jmc 852: be specified through certificate options.
1.93 djm 853: A certificate option may disable features of the SSH session, may be
1.84 djm 854: valid only when presented from particular source addresses or may
855: force the use of a specific command.
1.93 djm 856: For a list of valid certificate options, see the documentation for the
1.84 djm 857: .Fl O
858: option above.
859: .Pp
860: Finally, certificates may be defined with a validity lifetime.
861: The
862: .Fl V
863: option allows specification of certificate start and end times.
864: A certificate that is presented at a time outside this range will not be
865: considered valid.
1.110 jmc 866: By default, certificates are valid from
867: .Ux
868: Epoch to the distant future.
1.84 djm 869: .Pp
870: For certificates to be used for user or host authentication, the CA
871: public key must be trusted by
872: .Xr sshd 8
873: or
874: .Xr ssh 1 .
875: Please refer to those manual pages for details.
1.111 djm 876: .Sh KEY REVOCATION LISTS
877: .Nm
878: is able to manage OpenSSH format Key Revocation Lists (KRLs).
879: These binary files specify keys or certificates to be revoked using a
1.119 tedu 880: compact format, taking as little as one bit per certificate if they are being
1.111 djm 881: revoked by serial number.
882: .Pp
883: KRLs may be generated using the
884: .Fl k
885: flag.
1.114 jmc 886: This option reads one or more files from the command line and generates a new
1.111 djm 887: KRL.
888: The files may either contain a KRL specification (see below) or public keys,
889: listed one per line.
890: Plain public keys are revoked by listing their hash or contents in the KRL and
891: certificates revoked by serial number or key ID (if the serial is zero or
892: not available).
893: .Pp
894: Revoking keys using a KRL specification offers explicit control over the
895: types of record used to revoke keys and may be used to directly revoke
896: certificates by serial number or key ID without having the complete original
897: certificate on hand.
898: A KRL specification consists of lines containing one of the following directives
899: followed by a colon and some directive-specific information.
900: .Bl -tag -width Ds
1.115 jmc 901: .It Cm serial : Ar serial_number Ns Op - Ns Ar serial_number
1.111 djm 902: Revokes a certificate with the specified serial number.
1.112 jmc 903: Serial numbers are 64-bit values, not including zero and may be expressed
1.111 djm 904: in decimal, hex or octal.
905: If two serial numbers are specified separated by a hyphen, then the range
906: of serial numbers including and between each is revoked.
907: The CA key must have been specified on the
908: .Nm
1.114 jmc 909: command line using the
1.111 djm 910: .Fl s
911: option.
912: .It Cm id : Ar key_id
913: Revokes a certificate with the specified key ID string.
914: The CA key must have been specified on the
915: .Nm
1.114 jmc 916: command line using the
1.111 djm 917: .Fl s
918: option.
919: .It Cm key : Ar public_key
920: Revokes the specified key.
1.112 jmc 921: If a certificate is listed, then it is revoked as a plain public key.
1.111 djm 922: .It Cm sha1 : Ar public_key
1.149 djm 923: Revokes the specified key by including its SHA1 hash in the KRL.
924: .It Cm sha256 : Ar public_key
925: Revokes the specified key by including its SHA256 hash in the KRL.
926: KRLs that revoke keys by SHA256 hash are not supported by OpenSSH versions
927: prior to 7.9.
928: .It Cm hash : Ar fingerprint
1.150 djm 929: Revokes a key using a fingerprint hash, as obtained from a
1.149 djm 930: .Xr sshd 8
931: authentication log message or the
932: .Nm
933: .Fl l
934: flag.
935: Only SHA256 fingerprints are supported here and resultant KRLs are
936: not supported by OpenSSH versions prior to 7.9.
1.111 djm 937: .El
938: .Pp
939: KRLs may be updated using the
940: .Fl u
941: flag in addition to
942: .Fl k .
1.114 jmc 943: When this option is specified, keys listed via the command line are merged into
1.111 djm 944: the KRL, adding to those already there.
945: .Pp
946: It is also possible, given a KRL, to test whether it revokes a particular key
947: (or keys).
948: The
949: .Fl Q
1.128 jmc 950: flag will query an existing KRL, testing each key specified on the command line.
1.114 jmc 951: If any key listed on the command line has been revoked (or an error encountered)
1.111 djm 952: then
953: .Nm
954: will exit with a non-zero exit status.
955: A zero exit status will only be returned if no key was revoked.
1.163 djm 956: .Sh ALLOWED SIGNERS
957: When verifying signatures,
958: .Nm
959: uses a simple list of identities and keys to determine whether a signature
960: comes from an authorized source.
961: This "allowed signers" file uses a format patterned after the
962: AUTHORIZED_KEYS FILE FORMAT described in
1.165 jmc 963: .Xr sshd 8 .
1.163 djm 964: Each line of the file contains the following space-separated fields:
965: principals, options, keytype, base64-encoded key.
966: Empty lines and lines starting with a
967: .Ql #
968: are ignored as comments.
969: .Pp
970: The principals field is a pattern-list (See PATTERNS in
971: .Xr ssh_config 5 )
972: consisting of one or more comma-separated USER@DOMAIN identity patterns
973: that are accepted for signing.
974: When verifying, the identity presented via the
975: .Fl I option
976: must match a principals pattern in order for the corresponding key to be
977: considered acceptable for verification.
978: .Pp
979: The options (if present) consist of comma-separated option specifications.
980: No spaces are permitted, except within double quotes.
981: The following option specifications are supported (note that option keywords
982: are case-insensitive):
983: .Bl -tag -width Ds
984: .It Cm cert-authority
985: Indicates that this key is accepted as a certificate authority (CA) and
986: that certificates signed by this CA may be accepted for verification.
987: .It Cm namespaces="namespace-list"
988: Specifies a pattern-list of namespaces that are accepted for this key.
1.164 djm 989: If this option is present, the signature namespace embedded in the
1.163 djm 990: signature object and presented on the verification command-line must
991: match the specified list before the key will be considered acceptable.
992: .El
993: .Pp
994: When verifying signatures made by certificates, the expected principal
995: name must match both the principals pattern in the allowed signers file and
996: the principals embedded in the certificate itself.
997: .Pp
998: An example allowed signers file:
999: .Bd -literal -offset 3n
1000: # Comments allowed at start of line
1001: user1@example.com,user2@example.com ssh-rsa AAAAX1...
1002: # A certificate authority, trusted for all principals in a domain.
1003: *@example.com cert-authority ssh-ed25519 AAAB4...
1004: # A key that is accepted only for file signing.
1005: user2@example.com namespaces="file" ssh-ed25519 AAA41...
1006: .Ed
1.2 deraadt 1007: .Sh FILES
1.100 naddy 1008: .Bl -tag -width Ds -compact
1.68 djm 1009: .It Pa ~/.ssh/id_dsa
1.100 naddy 1010: .It Pa ~/.ssh/id_ecdsa
1.118 naddy 1011: .It Pa ~/.ssh/id_ed25519
1.100 naddy 1012: .It Pa ~/.ssh/id_rsa
1.141 naddy 1013: Contains the DSA, ECDSA, Ed25519 or RSA
1.118 naddy 1014: authentication identity of the user.
1.15 deraadt 1015: This file should not be readable by anyone but the user.
1016: It is possible to
1017: specify a passphrase when generating the key; that passphrase will be
1.80 dtucker 1018: used to encrypt the private part of this file using 128-bit AES.
1.15 deraadt 1019: This file is not automatically accessed by
1020: .Nm
1021: but it is offered as the default file for the private key.
1.46 markus 1022: .Xr ssh 1
1.15 deraadt 1023: will read this file when a login attempt is made.
1.100 naddy 1024: .Pp
1.68 djm 1025: .It Pa ~/.ssh/id_dsa.pub
1.100 naddy 1026: .It Pa ~/.ssh/id_ecdsa.pub
1.118 naddy 1027: .It Pa ~/.ssh/id_ed25519.pub
1.68 djm 1028: .It Pa ~/.ssh/id_rsa.pub
1.141 naddy 1029: Contains the DSA, ECDSA, Ed25519 or RSA
1.118 naddy 1030: public key for authentication.
1.15 deraadt 1031: The contents of this file should be added to
1.68 djm 1032: .Pa ~/.ssh/authorized_keys
1.15 deraadt 1033: on all machines
1.49 deraadt 1034: where the user wishes to log in using public key authentication.
1.12 aaron 1035: There is no need to keep the contents of this file secret.
1.100 naddy 1036: .Pp
1.60 djm 1037: .It Pa /etc/moduli
1038: Contains Diffie-Hellman groups used for DH-GEX.
1039: The file format is described in
1040: .Xr moduli 5 .
1.19 aaron 1041: .El
1.2 deraadt 1042: .Sh SEE ALSO
1043: .Xr ssh 1 ,
1044: .Xr ssh-add 1 ,
1.8 ericj 1045: .Xr ssh-agent 1 ,
1.60 djm 1046: .Xr moduli 5 ,
1.30 itojun 1047: .Xr sshd 8
1.37 markus 1048: .Rs
1.73 markus 1049: .%R RFC 4716
1050: .%T "The Secure Shell (SSH) Public Key File Format"
1051: .%D 2006
1.37 markus 1052: .Re
1.59 jmc 1053: .Sh AUTHORS
1054: OpenSSH is a derivative of the original and free
1055: ssh 1.2.12 release by Tatu Ylonen.
1056: Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos,
1057: Theo de Raadt and Dug Song
1058: removed many bugs, re-added newer features and
1059: created OpenSSH.
1060: Markus Friedl contributed the support for SSH
1061: protocol versions 1.5 and 2.0.