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