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