]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - crypto/openssh/ssh-keygen.1
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / crypto / openssh / ssh-keygen.1
1 .\"     $OpenBSD: ssh-keygen.1,v 1.88 2010/03/08 00:28:55 djm Exp $
2 .\"     $FreeBSD$
3 .\"
4 .\"  -*- nroff -*-
5 .\"
6 .\" Author: Tatu Ylonen <ylo@cs.hut.fi>
7 .\" Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 .\"                    All rights reserved
9 .\"
10 .\" As far as I am concerned, the code I have written for this software
11 .\" can be used freely for any purpose.  Any derived versions of this
12 .\" software must be clearly marked as such, and if the derived work is
13 .\" incompatible with the protocol description in the RFC file, it must be
14 .\" called by a name other than "ssh" or "Secure Shell".
15 .\"
16 .\"
17 .\" Copyright (c) 1999,2000 Markus Friedl.  All rights reserved.
18 .\" Copyright (c) 1999 Aaron Campbell.  All rights reserved.
19 .\" Copyright (c) 1999 Theo de Raadt.  All rights reserved.
20 .\"
21 .\" Redistribution and use in source and binary forms, with or without
22 .\" modification, are permitted provided that the following conditions
23 .\" are met:
24 .\" 1. Redistributions of source code must retain the above copyright
25 .\"    notice, this list of conditions and the following disclaimer.
26 .\" 2. Redistributions in binary form must reproduce the above copyright
27 .\"    notice, this list of conditions and the following disclaimer in the
28 .\"    documentation and/or other materials provided with the distribution.
29 .\"
30 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
31 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
33 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
34 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
39 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 .\"
41 .Dd March 8, 2010
42 .Dt SSH-KEYGEN 1
43 .Os
44 .Sh NAME
45 .Nm ssh-keygen
46 .Nd authentication key generation, management and conversion
47 .Sh SYNOPSIS
48 .Nm ssh-keygen
49 .Bk -words
50 .Op Fl q
51 .Op Fl b Ar bits
52 .Fl t Ar type
53 .Op Fl N Ar new_passphrase
54 .Op Fl C Ar comment
55 .Op Fl f Ar output_keyfile
56 .Nm ssh-keygen
57 .Fl p
58 .Op Fl P Ar old_passphrase
59 .Op Fl N Ar new_passphrase
60 .Op Fl f Ar keyfile
61 .Nm ssh-keygen
62 .Fl i
63 .Op Fl f Ar input_keyfile
64 .Nm ssh-keygen
65 .Fl e
66 .Op Fl f Ar input_keyfile
67 .Nm ssh-keygen
68 .Fl y
69 .Op Fl f Ar input_keyfile
70 .Nm ssh-keygen
71 .Fl c
72 .Op Fl P Ar passphrase
73 .Op Fl C Ar comment
74 .Op Fl f Ar keyfile
75 .Nm ssh-keygen
76 .Fl l
77 .Op Fl f Ar input_keyfile
78 .Nm ssh-keygen
79 .Fl B
80 .Op Fl f Ar input_keyfile
81 .Nm ssh-keygen
82 .Fl D Ar pkcs11
83 .Nm ssh-keygen
84 .Fl F Ar hostname
85 .Op Fl f Ar known_hosts_file
86 .Op Fl l
87 .Nm ssh-keygen
88 .Fl H
89 .Op Fl f Ar known_hosts_file
90 .Nm ssh-keygen
91 .Fl R Ar hostname
92 .Op Fl f Ar known_hosts_file
93 .Nm ssh-keygen
94 .Fl r Ar hostname
95 .Op Fl f Ar input_keyfile
96 .Op Fl g
97 .Nm ssh-keygen
98 .Fl G Ar output_file
99 .Op Fl v
100 .Op Fl b Ar bits
101 .Op Fl M Ar memory
102 .Op Fl S Ar start_point
103 .Nm ssh-keygen
104 .Fl T Ar output_file
105 .Fl f Ar input_file
106 .Op Fl v
107 .Op Fl a Ar num_trials
108 .Op Fl W Ar generator
109 .Nm ssh-keygen
110 .Fl s Ar ca_key
111 .Fl I Ar certificate_identity
112 .Op Fl h
113 .Op Fl n Ar principals
114 .Op Fl O Ar constraint
115 .Op Fl V Ar validity_interval
116 .Ar
117 .Nm ssh-keygen
118 .Fl L
119 .Op Fl f Ar input_keyfile
120 .Ek
121 .Sh DESCRIPTION
122 .Nm
123 generates, manages and converts authentication keys for
124 .Xr ssh 1 .
125 .Nm
126 can create RSA keys for use by SSH protocol version 1 and RSA or DSA
127 keys for use by SSH protocol version 2.
128 The type of key to be generated is specified with the
129 .Fl t
130 option.
131 If invoked without any arguments,
132 .Nm
133 will generate an RSA key for use in SSH protocol 2 connections.
134 .Pp
135 .Nm
136 is also used to generate groups for use in Diffie-Hellman group
137 exchange (DH-GEX).
138 See the
139 .Sx MODULI GENERATION
140 section for details.
141 .Pp
142 Normally each user wishing to use SSH
143 with RSA or DSA authentication runs this once to create the authentication
144 key in
145 .Pa ~/.ssh/identity ,
146 .Pa ~/.ssh/id_dsa
147 or
148 .Pa ~/.ssh/id_rsa .
149 Additionally, the system administrator may use this to generate host keys,
150 as seen in
151 .Pa /etc/rc .
152 .Pp
153 Normally this program generates the key and asks for a file in which
154 to store the private key.
155 The public key is stored in a file with the same name but
156 .Dq .pub
157 appended.
158 The program also asks for a passphrase.
159 The passphrase may be empty to indicate no passphrase
160 (host keys must have an empty passphrase), or it may be a string of
161 arbitrary length.
162 A passphrase is similar to a password, except it can be a phrase with a
163 series of words, punctuation, numbers, whitespace, or any string of
164 characters you want.
165 Good passphrases are 10-30 characters long, are
166 not simple sentences or otherwise easily guessable (English
167 prose has only 1-2 bits of entropy per character, and provides very bad
168 passphrases), and contain a mix of upper and lowercase letters,
169 numbers, and non-alphanumeric characters.
170 The passphrase can be changed later by using the
171 .Fl p
172 option.
173 .Pp
174 There is no way to recover a lost passphrase.
175 If the passphrase is
176 lost or forgotten, a new key must be generated and copied to the
177 corresponding public key to other machines.
178 .Pp
179 For RSA1 keys,
180 there is also a comment field in the key file that is only for
181 convenience to the user to help identify the key.
182 The comment can tell what the key is for, or whatever is useful.
183 The comment is initialized to
184 .Dq user@host
185 when the key is created, but can be changed using the
186 .Fl c
187 option.
188 .Pp
189 After a key is generated, instructions below detail where the keys
190 should be placed to be activated.
191 .Pp
192 The options are as follows:
193 .Bl -tag -width Ds
194 .It Fl a Ar trials
195 Specifies the number of primality tests to perform when screening DH-GEX
196 candidates using the
197 .Fl T
198 command.
199 .It Fl B
200 Show the bubblebabble digest of specified private or public key file.
201 .It Fl b Ar bits
202 Specifies the number of bits in the key to create.
203 For RSA keys, the minimum size is 768 bits and the default is 2048 bits.
204 Generally, 2048 bits is considered sufficient.
205 DSA keys must be exactly 1024 bits as specified by FIPS 186-2.
206 .It Fl C Ar comment
207 Provides a new comment.
208 .It Fl c
209 Requests changing the comment in the private and public key files.
210 This operation is only supported for RSA1 keys.
211 The program will prompt for the file containing the private keys, for
212 the passphrase if the key has one, and for the new comment.
213 .It Fl D Ar pkcs11
214 Download the RSA public keys provided by the PKCS#11 shared library
215 .Ar pkcs11 .
216 .It Fl e
217 This option will read a private or public OpenSSH key file and
218 print the key in
219 RFC 4716 SSH Public Key File Format
220 to stdout.
221 This option allows exporting keys for use by several commercial
222 SSH implementations.
223 .It Fl F Ar hostname
224 Search for the specified
225 .Ar hostname
226 in a
227 .Pa known_hosts
228 file, listing any occurrences found.
229 This option is useful to find hashed host names or addresses and may also be
230 used in conjunction with the
231 .Fl H
232 option to print found keys in a hashed format.
233 .It Fl f Ar filename
234 Specifies the filename of the key file.
235 .It Fl G Ar output_file
236 Generate candidate primes for DH-GEX.
237 These primes must be screened for
238 safety (using the
239 .Fl T
240 option) before use.
241 .It Fl g
242 Use generic DNS format when printing fingerprint resource records using the
243 .Fl r
244 command.
245 .It Fl H
246 Hash a
247 .Pa known_hosts
248 file.
249 This replaces all hostnames and addresses with hashed representations
250 within the specified file; the original content is moved to a file with
251 a .old suffix.
252 These hashes may be used normally by
253 .Nm ssh
254 and
255 .Nm sshd ,
256 but they do not reveal identifying information should the file's contents
257 be disclosed.
258 This option will not modify existing hashed hostnames and is therefore safe
259 to use on files that mix hashed and non-hashed names.
260 .It Fl h
261 When signing a key, create a host certificate instead of a user
262 certificate.
263 Please see the
264 .Sx CERTIFICATES
265 section for details.
266 .It Fl I Ar certificate_identity
267 Specify the key identity when signing a public key.
268 Please see the
269 .Sx CERTIFICATES
270 section for details.
271 .It Fl i
272 This option will read an unencrypted private (or public) key file
273 in SSH2-compatible format and print an OpenSSH compatible private
274 (or public) key to stdout.
275 .Nm
276 also reads the
277 RFC 4716 SSH Public Key File Format.
278 This option allows importing keys from several commercial
279 SSH implementations.
280 .It Fl L
281 Prints the contents of a certificate.
282 .It Fl l
283 Show fingerprint of specified public key file.
284 Private RSA1 keys are also supported.
285 For RSA and DSA keys
286 .Nm
287 tries to find the matching public key file and prints its fingerprint.
288 If combined with
289 .Fl v ,
290 an ASCII art representation of the key is supplied with the fingerprint.
291 .It Fl M Ar memory
292 Specify the amount of memory to use (in megabytes) when generating
293 candidate moduli for DH-GEX.
294 .It Fl N Ar new_passphrase
295 Provides the new passphrase.
296 .It Fl n Ar principals
297 Specify one or more principals (user or host names) to be included in
298 a certificate when signing a key.
299 Multiple principals may be specified, separated by commas.
300 Please see the
301 .Sx CERTIFICATES
302 section for details.
303 .It Fl O Ar constraint
304 Specify a certificate constraint when signing a key.
305 This option may be specified multiple times.
306 Please see the
307 .Sx CERTIFICATES
308 section for details.
309 The constraints that are valid for user certificates are:
310 .Bl -tag -width Ds
311 .It Ic no-x11-forwarding
312 Disable X11 forwarding (permitted by default).
313 .It Ic no-agent-forwarding
314 Disable
315 .Xr ssh-agent 1
316 forwarding (permitted by default).
317 .It Ic no-port-forwarding
318 Disable port forwarding (permitted by default).
319 .It Ic no-pty
320 Disable PTY allocation (permitted by default).
321 .It Ic no-user-rc
322 Disable execution of
323 .Pa ~/.ssh/rc
324 by
325 .Xr sshd 8
326 (permitted by default).
327 .It Ic clear
328 Clear all enabled permissions.
329 This is useful for clearing the default set of permissions so permissions may
330 be added individually.
331 .It Ic permit-x11-forwarding
332 Allows X11 forwarding.
333 .It Ic permit-agent-forwarding
334 Allows
335 .Xr ssh-agent 1
336 forwarding.
337 .It Ic permit-port-forwarding
338 Allows port forwarding.
339 .It Ic permit-pty
340 Allows PTY allocation.
341 .It Ic permit-user-rc
342 Allows execution of
343 .Pa ~/.ssh/rc
344 by
345 .Xr sshd 8 .
346 .It Ic force-command=command
347 Forces the execution of
348 .Ar command
349 instead of any shell or command specified by the user when
350 the certificate is used for authentication.
351 .It Ic source-address=address_list
352 Restrict the source addresses from which the certificate is considered valid
353 from.
354 The
355 .Ar address_list
356 is a comma-separated list of one or more address/netmask pairs in CIDR
357 format.
358 .El
359 .Pp
360 At present, no constraints are valid for host keys.
361 .It Fl P Ar passphrase
362 Provides the (old) passphrase.
363 .It Fl p
364 Requests changing the passphrase of a private key file instead of
365 creating a new private key.
366 The program will prompt for the file
367 containing the private key, for the old passphrase, and twice for the
368 new passphrase.
369 .It Fl q
370 Silence
371 .Nm ssh-keygen .
372 Used by
373 .Pa /etc/rc
374 when creating a new key.
375 .It Fl R Ar hostname
376 Removes all keys belonging to
377 .Ar hostname
378 from a
379 .Pa known_hosts
380 file.
381 This option is useful to delete hashed hosts (see the
382 .Fl H
383 option above).
384 .It Fl r Ar hostname
385 Print the SSHFP fingerprint resource record named
386 .Ar hostname
387 for the specified public key file.
388 .It Fl S Ar start
389 Specify start point (in hex) when generating candidate moduli for DH-GEX.
390 .It Fl s Ar ca_key
391 Certify (sign) a public key using the specified CA key.
392 Please see the
393 .Sx CERTIFICATES
394 section for details.
395 .It Fl T Ar output_file
396 Test DH group exchange candidate primes (generated using the
397 .Fl G
398 option) for safety.
399 .It Fl t Ar type
400 Specifies the type of key to create.
401 The possible values are
402 .Dq rsa1
403 for protocol version 1 and
404 .Dq rsa
405 or
406 .Dq dsa
407 for protocol version 2.
408 .It Fl V Ar validity_interval
409 Specify a validity interval when signing a certificate.
410 A validity interval may consist of a single time, indicating that the
411 certificate is valid beginning now and expiring at that time, or may consist
412 of two times separated by a colon to indicate an explicit time interval.
413 The start time may be specified as a date in YYYYMMDD format, a time
414 in YYYYMMDDHHMMSS format or a relative time (to the current time) consisting
415 of a minus sign followed by a relative time in the format described in the
416 .Sx TIME FORMATS
417 section of
418 .Xr ssh_config 5 .
419 The end time may be specified as a YYYYMMDD date, a YYYYMMDDHHMMSS time or
420 a relative time starting with a plus character.
421 .Pp
422 For example:
423 .Dq +52w1d
424 (valid from now to 52 weeks and one day from now),
425 .Dq -4w:+4w
426 (valid from four weeks ago to four weeks from now),
427 .Dq 20100101123000:20110101123000
428 (valid from 12:30 PM, January 1st, 2010 to 12:30 PM, January 1st, 2011),
429 .Dq -1d:20110101
430 (valid from yesterday to midnight, January 1st, 2011).
431 .It Fl v
432 Verbose mode.
433 Causes
434 .Nm
435 to print debugging messages about its progress.
436 This is helpful for debugging moduli generation.
437 Multiple
438 .Fl v
439 options increase the verbosity.
440 The maximum is 3.
441 .It Fl W Ar generator
442 Specify desired generator when testing candidate moduli for DH-GEX.
443 .It Fl y
444 This option will read a private
445 OpenSSH format file and print an OpenSSH public key to stdout.
446 .El
447 .Sh MODULI GENERATION
448 .Nm
449 may be used to generate groups for the Diffie-Hellman Group Exchange
450 (DH-GEX) protocol.
451 Generating these groups is a two-step process: first, candidate
452 primes are generated using a fast, but memory intensive process.
453 These candidate primes are then tested for suitability (a CPU-intensive
454 process).
455 .Pp
456 Generation of primes is performed using the
457 .Fl G
458 option.
459 The desired length of the primes may be specified by the
460 .Fl b
461 option.
462 For example:
463 .Pp
464 .Dl # ssh-keygen -G moduli-2048.candidates -b 2048
465 .Pp
466 By default, the search for primes begins at a random point in the
467 desired length range.
468 This may be overridden using the
469 .Fl S
470 option, which specifies a different start point (in hex).
471 .Pp
472 Once a set of candidates have been generated, they must be tested for
473 suitability.
474 This may be performed using the
475 .Fl T
476 option.
477 In this mode
478 .Nm
479 will read candidates from standard input (or a file specified using the
480 .Fl f
481 option).
482 For example:
483 .Pp
484 .Dl # ssh-keygen -T moduli-2048 -f moduli-2048.candidates
485 .Pp
486 By default, each candidate will be subjected to 100 primality tests.
487 This may be overridden using the
488 .Fl a
489 option.
490 The DH generator value will be chosen automatically for the
491 prime under consideration.
492 If a specific generator is desired, it may be requested using the
493 .Fl W
494 option.
495 Valid generator values are 2, 3, and 5.
496 .Pp
497 Screened DH groups may be installed in
498 .Pa /etc/moduli .
499 It is important that this file contains moduli of a range of bit lengths and
500 that both ends of a connection share common moduli.
501 .Sh CERTIFICATES
502 .Nm
503 supports signing of keys to produce certificates that may be used for
504 user or host authentication.
505 Certificates consist of a public key, some identity information, zero or
506 more principal (user or host) names and an optional set of constraints that
507 are signed by a Certification Authority (CA) key.
508 Clients or servers may then trust only the CA key and verify its signature
509 on a certificate rather than trusting many user/host keys.
510 Note that OpenSSH certificates are a different, and much simpler, format to
511 the X.509 certificates used in
512 .Xr ssl 8 .
513 .Pp
514 .Nm
515 supports two types of certificates: user and host.
516 User certificates authenticate users to servers, whereas host certificates
517 authenticate server hosts to users.
518 To generate a user certificate:
519 .Pp
520 .Dl $ ssh-keygen -s /path/to/ca_key -I key_id /path/to/user_key.pub
521 .Pp
522 The resultant certificate will be placed in
523 .Pa /path/to/user_key_cert.pub .
524 A host certificate requires the
525 .Fl h
526 option:
527 .Pp
528 .Dl $ ssh-keygen -s /path/to/ca_key -I key_id -h /path/to/host_key.pub
529 .Pp
530 The host certificate will be output to
531 .Pa /path/to/host_key_cert.pub .
532 In both cases,
533 .Ar key_id
534 is a "key identifier" that is logged by the server when the certificate
535 is used for authentication.
536 .Pp
537 Certificates may be limited to be valid for a set of principal (user/host)
538 names.
539 By default, generated certificates are valid for all users or hosts.
540 To generate a certificate for a specified set of principals:
541 .Pp
542 .Dl $ ssh-keygen -s ca_key -I key_id -n user1,user2 user_key.pub
543 .Dl $ ssh-keygen -s ca_key -I key_id -h -n host.domain user_key.pub
544 .Pp
545 Additional limitations on the validity and use of user certificates may
546 be specified through certificate constraints.
547 A constrained certificate may disable features of the SSH session, may be
548 valid only when presented from particular source addresses or may
549 force the use of a specific command.
550 For a list of valid certificate constraints, see the documentation for the
551 .Fl O
552 option above.
553 .Pp
554 Finally, certificates may be defined with a validity lifetime.
555 The
556 .Fl V
557 option allows specification of certificate start and end times.
558 A certificate that is presented at a time outside this range will not be
559 considered valid.
560 By default, certificates have a maximum validity interval.
561 .Pp
562 For certificates to be used for user or host authentication, the CA
563 public key must be trusted by
564 .Xr sshd 8
565 or
566 .Xr ssh 1 .
567 Please refer to those manual pages for details.
568 .Sh FILES
569 .Bl -tag -width Ds
570 .It Pa ~/.ssh/identity
571 Contains the protocol version 1 RSA authentication identity of the user.
572 This file should not be readable by anyone but the user.
573 It is possible to
574 specify a passphrase when generating the key; that passphrase will be
575 used to encrypt the private part of this file using 128-bit AES.
576 This file is not automatically accessed by
577 .Nm
578 but it is offered as the default file for the private key.
579 .Xr ssh 1
580 will read this file when a login attempt is made.
581 .It Pa ~/.ssh/identity.pub
582 Contains the protocol version 1 RSA public key for authentication.
583 The contents of this file should be added to
584 .Pa ~/.ssh/authorized_keys
585 on all machines
586 where the user wishes to log in using RSA authentication.
587 There is no need to keep the contents of this file secret.
588 .It Pa ~/.ssh/id_dsa
589 Contains the protocol version 2 DSA authentication identity of the user.
590 This file should not be readable by anyone but the user.
591 It is possible to
592 specify a passphrase when generating the key; that passphrase will be
593 used to encrypt the private part of this file using 128-bit AES.
594 This file is not automatically accessed by
595 .Nm
596 but it is offered as the default file for the private key.
597 .Xr ssh 1
598 will read this file when a login attempt is made.
599 .It Pa ~/.ssh/id_dsa.pub
600 Contains the protocol version 2 DSA public key for authentication.
601 The contents of this file should be added to
602 .Pa ~/.ssh/authorized_keys
603 on all machines
604 where the user wishes to log in using public key authentication.
605 There is no need to keep the contents of this file secret.
606 .It Pa ~/.ssh/id_rsa
607 Contains the protocol version 2 RSA authentication identity of the user.
608 This file should not be readable by anyone but the user.
609 It is possible to
610 specify a passphrase when generating the key; that passphrase will be
611 used to encrypt the private part of this file using 128-bit AES.
612 This file is not automatically accessed by
613 .Nm
614 but it is offered as the default file for the private key.
615 .Xr ssh 1
616 will read this file when a login attempt is made.
617 .It Pa ~/.ssh/id_rsa.pub
618 Contains the protocol version 2 RSA public key for authentication.
619 The contents of this file should be added to
620 .Pa ~/.ssh/authorized_keys
621 on all machines
622 where the user wishes to log in using public key authentication.
623 There is no need to keep the contents of this file secret.
624 .It Pa /etc/moduli
625 Contains Diffie-Hellman groups used for DH-GEX.
626 The file format is described in
627 .Xr moduli 5 .
628 .El
629 .Sh SEE ALSO
630 .Xr ssh 1 ,
631 .Xr ssh-add 1 ,
632 .Xr ssh-agent 1 ,
633 .Xr moduli 5 ,
634 .Xr sshd 8
635 .Rs
636 .%R RFC 4716
637 .%T "The Secure Shell (SSH) Public Key File Format"
638 .%D 2006
639 .Re
640 .Sh AUTHORS
641 OpenSSH is a derivative of the original and free
642 ssh 1.2.12 release by Tatu Ylonen.
643 Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos,
644 Theo de Raadt and Dug Song
645 removed many bugs, re-added newer features and
646 created OpenSSH.
647 Markus Friedl contributed the support for SSH
648 protocol versions 1.5 and 2.0.