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