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