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