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