ssh-keygen.0 revision 204861
1228753SmmSSH-KEYGEN(1) OpenBSD Reference Manual SSH-KEYGEN(1) 2228753Smm 3228753SmmNAME 4228753Smm ssh-keygen - authentication key generation, management and conversion 5228753Smm 6228753SmmSYNOPSIS 7228753Smm ssh-keygen [-q] [-b bits] -t type [-N new_passphrase] [-C comment] 8228753Smm [-f output_keyfile] 9228753Smm ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile] 10228753Smm ssh-keygen -i [-f input_keyfile] 11228753Smm ssh-keygen -e [-f input_keyfile] 12228753Smm ssh-keygen -y [-f input_keyfile] 13228753Smm ssh-keygen -c [-P passphrase] [-C comment] [-f keyfile] 14228753Smm ssh-keygen -l [-f input_keyfile] 15228753Smm ssh-keygen -B [-f input_keyfile] 16228753Smm ssh-keygen -D pkcs11 17228753Smm ssh-keygen -F hostname [-f known_hosts_file] [-l] 18228753Smm ssh-keygen -H [-f known_hosts_file] 19228753Smm ssh-keygen -R hostname [-f known_hosts_file] 20228753Smm ssh-keygen -r hostname [-f input_keyfile] [-g] 21228753Smm ssh-keygen -G output_file [-v] [-b bits] [-M memory] [-S start_point] 22228753Smm ssh-keygen -T output_file -f input_file [-v] [-a num_trials] 23228753Smm [-W generator] 24228753Smm ssh-keygen -s ca_key -I certificate_identity [-h] [-n principals] 25228753Smm [-O constraint] [-V validity_interval] file ... 26228753Smm ssh-keygen -L [-f input_keyfile] 27228753Smm 28228753SmmDESCRIPTION 29228753Smm ssh-keygen generates, manages and converts authentication keys for 30228753Smm ssh(1). ssh-keygen can create RSA keys for use by SSH protocol version 1 31228753Smm and RSA or DSA keys for use by SSH protocol version 2. The type of key 32228753Smm to be generated is specified with the -t option. If invoked without any 33228753Smm arguments, ssh-keygen will generate an RSA key for use in SSH protocol 2 34228753Smm connections. 35228753Smm 36228753Smm ssh-keygen is also used to generate groups for use in Diffie-Hellman 37228753Smm group exchange (DH-GEX). See the MODULI GENERATION section for details. 38228753Smm 39228753Smm Normally each user wishing to use SSH with RSA or DSA authentication runs 40228753Smm this once to create the authentication key in ~/.ssh/identity, 41228753Smm ~/.ssh/id_dsa or ~/.ssh/id_rsa. Additionally, the system administrator 42228753Smm may use this to generate host keys, as seen in /etc/rc. 43228753Smm 44228753Smm Normally this program generates the key and asks for a file in which to 45228753Smm store the private key. The public key is stored in a file with the same 46228753Smm name but ``.pub'' appended. The program also asks for a passphrase. The 47228753Smm passphrase may be empty to indicate no passphrase (host keys must have an 48228753Smm empty passphrase), or it may be a string of arbitrary length. A 49228753Smm passphrase is similar to a password, except it can be a phrase with a se- 50228753Smm ries of words, punctuation, numbers, whitespace, or any string of charac- 51228753Smm ters you want. Good passphrases are 10-30 characters long, are not sim- 52228753Smm ple sentences or otherwise easily guessable (English prose has only 1-2 53228753Smm bits of entropy per character, and provides very bad passphrases), and 54228753Smm contain a mix of upper and lowercase letters, numbers, and non-alphanu- 55228753Smm meric characters. The passphrase can be changed later by using the -p 56228753Smm option. 57228753Smm 58228753Smm There is no way to recover a lost passphrase. If the passphrase is lost 59228753Smm or forgotten, a new key must be generated and copied to the corresponding 60228753Smm public key to other machines. 61228753Smm 62228753Smm For RSA1 keys, there is also a comment field in the key file that is only 63228753Smm for convenience to the user to help identify the key. The comment can 64228753Smm tell what the key is for, or whatever is useful. The comment is initial- 65228753Smm ized to ``user@host'' when the key is created, but can be changed using 66228753Smm the -c option. 67228753Smm 68228753Smm After a key is generated, instructions below detail where the keys should 69228753Smm be placed to be activated. 70228753Smm 71228753Smm The options are as follows: 72228753Smm 73228753Smm -a trials 74228753Smm Specifies the number of primality tests to perform when screening 75228753Smm DH-GEX candidates using the -T command. 76228753Smm 77228753Smm -B Show the bubblebabble digest of specified private or public key 78228753Smm file. 79228753Smm 80228753Smm -b bits 81228753Smm Specifies the number of bits in the key to create. For RSA keys, 82228753Smm the minimum size is 768 bits and the default is 2048 bits. Gen- 83228753Smm erally, 2048 bits is considered sufficient. DSA keys must be ex- 84228753Smm actly 1024 bits as specified by FIPS 186-2. 85228753Smm 86228753Smm -C comment 87228753Smm Provides a new comment. 88228753Smm 89228753Smm -c Requests changing the comment in the private and public key 90228753Smm files. This operation is only supported for RSA1 keys. The pro- 91228753Smm gram will prompt for the file containing the private keys, for 92228753Smm the passphrase if the key has one, and for the new comment. 93228753Smm 94228753Smm -D pkcs11 95228753Smm Download the RSA public keys provided by the PKCS#11 shared li- 96228753Smm brary pkcs11. 97228753Smm 98228753Smm -e This option will read a private or public OpenSSH key file and 99228753Smm print the key in RFC 4716 SSH Public Key File Format to stdout. 100228753Smm This option allows exporting keys for use by several commercial 101228753Smm SSH implementations. 102228753Smm 103228753Smm -F hostname 104228753Smm Search for the specified hostname in a known_hosts file, listing 105228753Smm any occurrences found. This option is useful to find hashed host 106228753Smm names or addresses and may also be used in conjunction with the 107228753Smm -H option to print found keys in a hashed format. 108228753Smm 109228753Smm -f filename 110228753Smm Specifies the filename of the key file. 111228753Smm 112228753Smm -G output_file 113228753Smm Generate candidate primes for DH-GEX. These primes must be 114228753Smm screened for safety (using the -T option) before use. 115228753Smm 116228753Smm -g Use generic DNS format when printing fingerprint resource records 117228753Smm using the -r command. 118228753Smm 119228753Smm -H Hash a known_hosts file. This replaces all hostnames and ad- 120228753Smm dresses with hashed representations within the specified file; 121228753Smm the original content is moved to a file with a .old suffix. 122228753Smm These hashes may be used normally by ssh and sshd, but they do 123228753Smm not reveal identifying information should the file's contents be 124228753Smm disclosed. This option will not modify existing hashed hostnames 125228753Smm and is therefore safe to use on files that mix hashed and non- 126228753Smm hashed names. 127228753Smm 128228753Smm -h When signing a key, create a host certificate instead of a user 129228753Smm certificate. Please see the CERTIFICATES section for details. 130228753Smm 131228753Smm -I certificate_identity 132228753Smm Specify the key identity when signing a public key. Please see 133228753Smm the CERTIFICATES section for details. 134228753Smm 135228753Smm -i This option will read an unencrypted private (or public) key file 136228753Smm in SSH2-compatible format and print an OpenSSH compatible private 137228753Smm (or public) key to stdout. ssh-keygen also reads the RFC 4716 138228753Smm SSH Public Key File Format. This option allows importing keys 139228753Smm from several commercial SSH implementations. 140228753Smm 141228753Smm -L Prints the contents of a certificate. 142228753Smm 143228753Smm -l Show fingerprint of specified public key file. Private RSA1 keys 144228753Smm are also supported. For RSA and DSA keys ssh-keygen tries to 145228753Smm find the matching public key file and prints its fingerprint. If 146228753Smm combined with -v, an ASCII art representation of the key is sup- 147228753Smm plied with the fingerprint. 148228753Smm 149228753Smm -M memory 150228753Smm Specify the amount of memory to use (in megabytes) when generat- 151228753Smm ing candidate moduli for DH-GEX. 152228753Smm 153228753Smm -N new_passphrase 154228753Smm Provides the new passphrase. 155228753Smm 156228753Smm -n principals 157228753Smm Specify one or more principals (user or host names) to be includ- 158228753Smm ed in a certificate when signing a key. Multiple principals may 159228753Smm be specified, separated by commas. Please see the CERTIFICATES 160228753Smm section for details. 161228753Smm 162228753Smm -O constraint 163228753Smm Specify a certificate constraint when signing a key. This option 164228753Smm may be specified multiple times. Please see the CERTIFICATES 165228753Smm section for details. The constraints that are valid for user 166228753Smm certificates are: 167228753Smm 168228753Smm no-x11-forwarding 169228753Smm Disable X11 forwarding (permitted by default). 170228753Smm 171228753Smm no-agent-forwarding 172228753Smm Disable ssh-agent(1) forwarding (permitted by default). 173228753Smm 174228753Smm no-port-forwarding 175228753Smm Disable port forwarding (permitted by default). 176228753Smm 177228753Smm no-pty Disable PTY allocation (permitted by default). 178228753Smm 179228753Smm no-user-rc 180228753Smm Disable execution of ~/.ssh/rc by sshd(8) (permitted by 181228753Smm default). 182228753Smm 183228753Smm clear Clear all enabled permissions. This is useful for clear- 184228753Smm ing the default set of permissions so permissions may be 185228753Smm added individually. 186228753Smm 187228753Smm permit-x11-forwarding 188228753Smm Allows X11 forwarding. 189228753Smm 190228753Smm permit-agent-forwarding 191228753Smm Allows ssh-agent(1) forwarding. 192228753Smm 193228753Smm permit-port-forwarding 194228753Smm Allows port forwarding. 195228753Smm 196228753Smm permit-pty 197228753Smm Allows PTY allocation. 198228753Smm 199 permit-user-rc 200 Allows execution of ~/.ssh/rc by sshd(8). 201 202 force-command=command 203 Forces the execution of command instead of any shell or 204 command specified by the user when the certificate is 205 used for authentication. 206 207 source-address=address_list 208 Restrict the source addresses from which the certificate 209 is considered valid from. The address_list is a comma- 210 separated list of one or more address/netmask pairs in 211 CIDR format. 212 213 At present, no constraints are valid for host keys. 214 215 -P passphrase 216 Provides the (old) passphrase. 217 218 -p Requests changing the passphrase of a private key file instead of 219 creating a new private key. The program will prompt for the file 220 containing the private key, for the old passphrase, and twice for 221 the new passphrase. 222 223 -q Silence ssh-keygen. Used by /etc/rc when creating a new key. 224 225 -R hostname 226 Removes all keys belonging to hostname from a known_hosts file. 227 This option is useful to delete hashed hosts (see the -H option 228 above). 229 230 -r hostname 231 Print the SSHFP fingerprint resource record named hostname for 232 the specified public key file. 233 234 -S start 235 Specify start point (in hex) when generating candidate moduli for 236 DH-GEX. 237 238 -s ca_key 239 Certify (sign) a public key using the specified CA key. Please 240 see the CERTIFICATES section for details. 241 242 -T output_file 243 Test DH group exchange candidate primes (generated using the -G 244 option) for safety. 245 246 -t type 247 Specifies the type of key to create. The possible values are 248 ``rsa1'' for protocol version 1 and ``rsa'' or ``dsa'' for proto- 249 col version 2. 250 251 -V validity_interval 252 Specify a validity interval when signing a certificate. A valid- 253 ity interval may consist of a single time, indicating that the 254 certificate is valid beginning now and expiring at that time, or 255 may consist of two times separated by a colon to indicate an ex- 256 plicit time interval. The start time may be specified as a date 257 in YYYYMMDD format, a time in YYYYMMDDHHMMSS format or a relative 258 time (to the current time) consisting of a minus sign followed by 259 a relative time in the format described in the TIME FORMATS sec- 260 tion of ssh_config(5). The end time may be specified as a YYYYM- 261 MDD date, a YYYYMMDDHHMMSS time or a relative time starting with 262 a plus character. 263 264 For example: ``+52w1d'' (valid from now to 52 weeks and one day 265 from now), ``-4w:+4w'' (valid from four weeks ago to four weeks 266 from now), ``20100101123000:20110101123000'' (valid from 12:30 267 PM, January 1st, 2010 to 12:30 PM, January 1st, 2011), 268 ``-1d:20110101'' (valid from yesterday to midnight, January 1st, 269 2011). 270 271 -v Verbose mode. Causes ssh-keygen to print debugging messages 272 about its progress. This is helpful for debugging moduli genera- 273 tion. Multiple -v options increase the verbosity. The maximum 274 is 3. 275 276 -W generator 277 Specify desired generator when testing candidate moduli for DH- 278 GEX. 279 280 -y This option will read a private OpenSSH format file and print an 281 OpenSSH public key to stdout. 282 283MODULI GENERATION 284 ssh-keygen may be used to generate groups for the Diffie-Hellman Group 285 Exchange (DH-GEX) protocol. Generating these groups is a two-step pro- 286 cess: first, candidate primes are generated using a fast, but memory in- 287 tensive process. These candidate primes are then tested for suitability 288 (a CPU-intensive process). 289 290 Generation of primes is performed using the -G option. The desired 291 length of the primes may be specified by the -b option. For example: 292 293 # ssh-keygen -G moduli-2048.candidates -b 2048 294 295 By default, the search for primes begins at a random point in the desired 296 length range. This may be overridden using the -S option, which speci- 297 fies a different start point (in hex). 298 299 Once a set of candidates have been generated, they must be tested for 300 suitability. This may be performed using the -T option. In this mode 301 ssh-keygen will read candidates from standard input (or a file specified 302 using the -f option). For example: 303 304 # ssh-keygen -T moduli-2048 -f moduli-2048.candidates 305 306 By default, each candidate will be subjected to 100 primality tests. 307 This may be overridden using the -a option. The DH generator value will 308 be chosen automatically for the prime under consideration. If a specific 309 generator is desired, it may be requested using the -W option. Valid 310 generator values are 2, 3, and 5. 311 312 Screened DH groups may be installed in /etc/moduli. It is important that 313 this file contains moduli of a range of bit lengths and that both ends of 314 a connection share common moduli. 315 316CERTIFICATES 317 ssh-keygen supports signing of keys to produce certificates that may be 318 used for user or host authentication. Certificates consist of a public 319 key, some identity information, zero or more principal (user or host) 320 names and an optional set of constraints that are signed by a Certifica- 321 tion Authority (CA) key. Clients or servers may then trust only the CA 322 key and verify its signature on a certificate rather than trusting many 323 user/host keys. Note that OpenSSH certificates are a different, and much 324 simpler, format to the X.509 certificates used in ssl(8). 325 326 ssh-keygen supports two types of certificates: user and host. User cer- 327 tificates authenticate users to servers, whereas host certificates au- 328 thenticate server hosts to users. To generate a user certificate: 329 330 $ ssh-keygen -s /path/to/ca_key -I key_id /path/to/user_key.pub 331 332 The resultant certificate will be placed in /path/to/user_key_cert.pub. 333 A host certificate requires the -h option: 334 335 $ ssh-keygen -s /path/to/ca_key -I key_id -h /path/to/host_key.pub 336 337 The host certificate will be output to /path/to/host_key_cert.pub. In 338 both cases, key_id is a "key identifier" that is logged by the server 339 when the certificate is used for authentication. 340 341 Certificates may be limited to be valid for a set of principal (us- 342 er/host) names. By default, generated certificates are valid for all 343 users or hosts. To generate a certificate for a specified set of princi- 344 pals: 345 346 $ ssh-keygen -s ca_key -I key_id -n user1,user2 user_key.pub 347 $ ssh-keygen -s ca_key -I key_id -h -n host.domain $0 348 349 Additional limitations on the validity and use of user certificates may 350 be specified through certificate constraints. A constrained certificate 351 may disable features of the SSH session, may be valid only when presented 352 from particular source addresses or may force the use of a specific com- 353 mand. For a list of valid certificate constraints, see the documentation 354 for the -O option above. 355 356 Finally, certificates may be defined with a validity lifetime. The -V 357 option allows specification of certificate start and end times. A cer- 358 tificate that is presented at a time outside this range will not be con- 359 sidered valid. By default, certificates have a maximum validity inter- 360 val. 361 362 For certificates to be used for user or host authentication, the CA pub- 363 lic key must be trusted by sshd(8) or ssh(1). Please refer to those man- 364 ual pages for details. 365 366FILES 367 ~/.ssh/identity 368 Contains the protocol version 1 RSA authentication identity of 369 the user. This file should not be readable by anyone but the us- 370 er. It is possible to specify a passphrase when generating the 371 key; that passphrase will be used to encrypt the private part of 372 this file using 128-bit AES. This file is not automatically ac- 373 cessed by ssh-keygen but it is offered as the default file for 374 the private key. ssh(1) will read this file when a login attempt 375 is made. 376 377 ~/.ssh/identity.pub 378 Contains the protocol version 1 RSA public key for authentica- 379 tion. The contents of this file should be added to 380 ~/.ssh/authorized_keys on all machines where the user wishes to 381 log in using RSA authentication. There is no need to keep the 382 contents of this file secret. 383 384 ~/.ssh/id_dsa 385 Contains the protocol version 2 DSA authentication identity of 386 the user. This file should not be readable by anyone but the us- 387 er. It is possible to specify a passphrase when generating the 388 key; that passphrase will be used to encrypt the private part of 389 this file using 128-bit AES. This file is not automatically ac- 390 cessed by ssh-keygen but it is offered as the default file for 391 the private key. ssh(1) will read this file when a login attempt 392 is made. 393 394 ~/.ssh/id_dsa.pub 395 Contains the protocol version 2 DSA public key for authentica- 396 tion. The contents of this file should be added to 397 ~/.ssh/authorized_keys on all machines where the user wishes to 398 log in using public key authentication. There is no need to keep 399 the contents of this file secret. 400 401 ~/.ssh/id_rsa 402 Contains the protocol version 2 RSA authentication identity of 403 the user. This file should not be readable by anyone but the us- 404 er. It is possible to specify a passphrase when generating the 405 key; that passphrase will be used to encrypt the private part of 406 this file using 128-bit AES. This file is not automatically ac- 407 cessed by ssh-keygen but it is offered as the default file for 408 the private key. ssh(1) will read this file when a login attempt 409 is made. 410 411 ~/.ssh/id_rsa.pub 412 Contains the protocol version 2 RSA public key for authentica- 413 tion. The contents of this file should be added to 414 ~/.ssh/authorized_keys on all machines where the user wishes to 415 log in using public key authentication. There is no need to keep 416 the contents of this file secret. 417 418 /etc/moduli 419 Contains Diffie-Hellman groups used for DH-GEX. The file format 420 is described in moduli(5). 421 422SEE ALSO 423 ssh(1), ssh-add(1), ssh-agent(1), moduli(5), sshd(8) 424 425 The Secure Shell (SSH) Public Key File Format, RFC 4716, 2006. 426 427AUTHORS 428 OpenSSH is a derivative of the original and free ssh 1.2.12 release by 429 Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo 430 de Raadt and Dug Song removed many bugs, re-added newer features and 431 created OpenSSH. Markus Friedl contributed the support for SSH protocol 432 versions 1.5 and 2.0. 433 434OpenBSD 4.6 March 8, 2010 7 435