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