1.\" 2.\" Author: Tatu Ylonen <ylo@cs.hut.fi> 3.\" Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4.\" All rights reserved 5.\" 6.\" As far as I am concerned, the code I have written for this software 7.\" can be used freely for any purpose. Any derived versions of this 8.\" software must be clearly marked as such, and if the derived work is 9.\" incompatible with the protocol description in the RFC file, it must be 10.\" called by a name other than "ssh" or "Secure Shell". 11.\" 12.\" Copyright (c) 1999,2000 Markus Friedl. All rights reserved. 13.\" Copyright (c) 1999 Aaron Campbell. All rights reserved. 14.\" Copyright (c) 1999 Theo de Raadt. All rights reserved. 15.\" 16.\" Redistribution and use in source and binary forms, with or without 17.\" modification, are permitted provided that the following conditions 18.\" are met: 19.\" 1. Redistributions of source code must retain the above copyright 20.\" notice, this list of conditions and the following disclaimer. 21.\" 2. Redistributions in binary form must reproduce the above copyright 22.\" notice, this list of conditions and the following disclaimer in the 23.\" documentation and/or other materials provided with the distribution. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 26.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 29.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35.\" 36.\" $OpenBSD: sshd.8,v 1.284 2016/02/17 07:38:19 jmc Exp $ 37.Dd $Mdocdate: February 17 2016 $ 38.Dt SSHD 8 39.Os 40.Sh NAME 41.Nm sshd 42.Nd OpenSSH SSH daemon 43.Sh SYNOPSIS 44.Nm sshd 45.Bk -words 46.Op Fl 46DdeiqTt 47.Op Fl b Ar bits 48.Op Fl C Ar connection_spec 49.Op Fl c Ar host_certificate_file 50.Op Fl E Ar log_file 51.Op Fl f Ar config_file 52.Op Fl g Ar login_grace_time 53.Op Fl h Ar host_key_file 54.Op Fl k Ar key_gen_time 55.Op Fl o Ar option 56.Op Fl p Ar port 57.Op Fl u Ar len 58.Ek 59.Sh DESCRIPTION 60.Nm 61(OpenSSH Daemon) is the daemon program for 62.Xr ssh 1 . 63Together these programs replace rlogin and rsh, 64and provide secure encrypted communications between two untrusted hosts 65over an insecure network. 66.Pp 67.Nm 68listens for connections from clients. 69It is normally started at boot from 70.Pa /etc/rc.d/sshd . 71It forks a new 72daemon for each incoming connection. 73The forked daemons handle 74key exchange, encryption, authentication, command execution, 75and data exchange. 76.Pp 77.Nm 78can be configured using command-line options or a configuration file 79(by default 80.Xr sshd_config 5 ) ; 81command-line options override values specified in the 82configuration file. 83.Nm 84rereads its configuration file when it receives a hangup signal, 85.Dv SIGHUP , 86by executing itself with the name and options it was started with, e.g.\& 87.Pa /usr/sbin/sshd . 88.Pp 89The options are as follows: 90.Bl -tag -width Ds 91.It Fl 4 92Forces 93.Nm 94to use IPv4 addresses only. 95.It Fl 6 96Forces 97.Nm 98to use IPv6 addresses only. 99.It Fl b Ar bits 100Specifies the number of bits in the ephemeral protocol version 1 101server key (default 1024). 102.It Fl C Ar connection_spec 103Specify the connection parameters to use for the 104.Fl T 105extended test mode. 106If provided, any 107.Cm Match 108directives in the configuration file 109that would apply to the specified user, host, and address will be set before 110the configuration is written to standard output. 111The connection parameters are supplied as keyword=value pairs. 112The keywords are 113.Dq user , 114.Dq host , 115.Dq laddr , 116.Dq lport , 117and 118.Dq addr . 119All are required and may be supplied in any order, either with multiple 120.Fl C 121options or as a comma-separated list. 122.It Fl c Ar host_certificate_file 123Specifies a path to a certificate file to identify 124.Nm 125during key exchange. 126The certificate file must match a host key file specified using the 127.Fl h 128option or the 129.Cm HostKey 130configuration directive. 131.It Fl D 132When this option is specified, 133.Nm 134will not detach and does not become a daemon. 135This allows easy monitoring of 136.Nm sshd . 137.It Fl d 138Debug mode. 139The server sends verbose debug output to standard error, 140and does not put itself in the background. 141The server also will not fork and will only process one connection. 142This option is only intended for debugging for the server. 143Multiple 144.Fl d 145options increase the debugging level. 146Maximum is 3. 147.It Fl E Ar log_file 148Append debug logs to 149.Ar log_file 150instead of the system log. 151.It Fl e 152Write debug logs to standard error instead of the system log. 153.It Fl f Ar config_file 154Specifies the name of the configuration file. 155The default is 156.Pa /etc/ssh/sshd_config . 157.Nm 158refuses to start if there is no configuration file. 159.It Fl g Ar login_grace_time 160Gives the grace time for clients to authenticate themselves (default 161120 seconds). 162If the client fails to authenticate the user within 163this many seconds, the server disconnects and exits. 164A value of zero indicates no limit. 165.It Fl h Ar host_key_file 166Specifies a file from which a host key is read. 167This option must be given if 168.Nm 169is not run as root (as the normal 170host key files are normally not readable by anyone but root). 171The default is 172.Pa /etc/ssh/ssh_host_key 173for protocol version 1, and 174.Pa /etc/ssh/ssh_host_dsa_key , 175.Pa /etc/ssh/ssh_host_ecdsa_key . 176.Pa /etc/ssh/ssh_host_ed25519_key 177and 178.Pa /etc/ssh/ssh_host_rsa_key 179for protocol version 2. 180It is possible to have multiple host key files for 181the different protocol versions and host key algorithms. 182.It Fl i 183Specifies that 184.Nm 185is being run from 186.Xr inetd 8 . 187If SSH protocol 1 is enabled, 188.Nm 189should not normally be run 190from inetd because it needs to generate the server key before it can 191respond to the client, and this may take some time. 192Clients may have to wait too long if the key was regenerated every time. 193.It Fl k Ar key_gen_time 194Specifies how often the ephemeral protocol version 1 server key is 195regenerated (default 3600 seconds, or one hour). 196The motivation for regenerating the key fairly 197often is that the key is not stored anywhere, and after about an hour 198it becomes impossible to recover the key for decrypting intercepted 199communications even if the machine is cracked into or physically 200seized. 201A value of zero indicates that the key will never be regenerated. 202.It Fl o Ar option 203Can be used to give options in the format used in the configuration file. 204This is useful for specifying options for which there is no separate 205command-line flag. 206For full details of the options, and their values, see 207.Xr sshd_config 5 . 208.It Fl p Ar port 209Specifies the port on which the server listens for connections 210(default 22). 211Multiple port options are permitted. 212Ports specified in the configuration file with the 213.Cm Port 214option are ignored when a command-line port is specified. 215Ports specified using the 216.Cm ListenAddress 217option override command-line ports. 218.It Fl q 219Quiet mode. 220Nothing is sent to the system log. 221Normally the beginning, 222authentication, and termination of each connection is logged. 223.It Fl T 224Extended test mode. 225Check the validity of the configuration file, output the effective configuration 226to stdout and then exit. 227Optionally, 228.Cm Match 229rules may be applied by specifying the connection parameters using one or more 230.Fl C 231options. 232.It Fl t 233Test mode. 234Only check the validity of the configuration file and sanity of the keys. 235This is useful for updating 236.Nm 237reliably as configuration options may change. 238.It Fl u Ar len 239This option is used to specify the size of the field 240in the 241.Li utmp 242structure that holds the remote host name. 243If the resolved host name is longer than 244.Ar len , 245the dotted decimal value will be used instead. 246This allows hosts with very long host names that 247overflow this field to still be uniquely identified. 248Specifying 249.Fl u0 250indicates that only dotted decimal addresses 251should be put into the 252.Pa utmp 253file. 254.Fl u0 255may also be used to prevent 256.Nm 257from making DNS requests unless the authentication 258mechanism or configuration requires it. 259Authentication mechanisms that may require DNS include 260.Cm RhostsRSAAuthentication , 261.Cm HostbasedAuthentication , 262and using a 263.Cm from="pattern-list" 264option in a key file. 265Configuration options that require DNS include using a 266USER@HOST pattern in 267.Cm AllowUsers 268or 269.Cm DenyUsers . 270.El 271.Sh AUTHENTICATION 272The OpenSSH SSH daemon supports SSH protocols 1 and 2. 273The default is to use protocol 2 only, 274though this can be changed via the 275.Cm Protocol 276option in 277.Xr sshd_config 5 . 278Protocol 1 should not be used 279and is only offered to support legacy devices. 280.Pp 281Each host has a host-specific key, 282used to identify the host. 283Partial forward security for protocol 1 is provided through 284an additional server key, 285normally 1024 bits, 286generated when the server starts. 287This key is normally regenerated every hour if it has been used, and 288is never stored on disk. 289Whenever a client connects, the daemon responds with its public 290host and server keys. 291The client compares the 292RSA host key against its own database to verify that it has not changed. 293The client then generates a 256-bit random number. 294It encrypts this 295random number using both the host key and the server key, and sends 296the encrypted number to the server. 297Both sides then use this 298random number as a session key which is used to encrypt all further 299communications in the session. 300The rest of the session is encrypted 301using a conventional cipher, currently Blowfish or 3DES, with 3DES 302being used by default. 303The client selects the encryption algorithm 304to use from those offered by the server. 305.Pp 306For protocol 2, 307forward security is provided through a Diffie-Hellman key agreement. 308This key agreement results in a shared session key. 309The rest of the session is encrypted using a symmetric cipher, currently 310128-bit AES, Blowfish, 3DES, CAST128, Arcfour, 192-bit AES, or 256-bit AES. 311The client selects the encryption algorithm 312to use from those offered by the server. 313Additionally, session integrity is provided 314through a cryptographic message authentication code 315(hmac-md5, hmac-sha1, umac-64, umac-128, hmac-ripemd160, 316hmac-sha2-256 or hmac-sha2-512). 317.Pp 318Finally, the server and the client enter an authentication dialog. 319The client tries to authenticate itself using 320host-based authentication, 321public key authentication, 322challenge-response authentication, 323or password authentication. 324.Pp 325Regardless of the authentication type, the account is checked to 326ensure that it is accessible. An account is not accessible if it is 327locked, listed in 328.Cm DenyUsers 329or its group is listed in 330.Cm DenyGroups 331\&. The definition of a locked account is system dependant. Some platforms 332have their own account database (eg AIX) and some modify the passwd field ( 333.Ql \&*LK\&* 334on Solaris and UnixWare, 335.Ql \&* 336on HP-UX, containing 337.Ql Nologin 338on Tru64, 339a leading 340.Ql \&*LOCKED\&* 341on FreeBSD and a leading 342.Ql \&! 343on most Linuxes). 344If there is a requirement to disable password authentication 345for the account while allowing still public-key, then the passwd field 346should be set to something other than these values (eg 347.Ql NP 348or 349.Ql \&*NP\&* 350). 351.Pp 352If the client successfully authenticates itself, a dialog for 353preparing the session is entered. 354At this time the client may request 355things like allocating a pseudo-tty, forwarding X11 connections, 356forwarding TCP connections, or forwarding the authentication agent 357connection over the secure channel. 358.Pp 359After this, the client either requests a shell or execution of a command. 360The sides then enter session mode. 361In this mode, either side may send 362data at any time, and such data is forwarded to/from the shell or 363command on the server side, and the user terminal in the client side. 364.Pp 365When the user program terminates and all forwarded X11 and other 366connections have been closed, the server sends command exit status to 367the client, and both sides exit. 368.Sh LOGIN PROCESS 369When a user successfully logs in, 370.Nm 371does the following: 372.Bl -enum -offset indent 373.It 374If the login is on a tty, and no command has been specified, 375prints last login time and 376.Pa /etc/motd 377(unless prevented in the configuration file or by 378.Pa ~/.hushlogin ; 379see the 380.Sx FILES 381section). 382.It 383If the login is on a tty, records login time. 384.It 385Checks 386.Pa /etc/nologin and 387.Pa /var/run/nologin ; 388if one exists, it prints the contents and quits 389(unless root). 390.It 391Changes to run with normal user privileges. 392.It 393Sets up basic environment. 394.It 395Reads the file 396.Pa ~/.ssh/environment , 397if it exists, and users are allowed to change their environment. 398See the 399.Cm PermitUserEnvironment 400option in 401.Xr sshd_config 5 . 402.It 403Changes to user's home directory. 404.It 405If 406.Pa ~/.ssh/rc 407exists and the 408.Xr sshd_config 5 409.Cm PermitUserRC 410option is set, runs it; else if 411.Pa /etc/ssh/sshrc 412exists, runs 413it; otherwise runs 414.Xr xauth 1 . 415The 416.Dq rc 417files are given the X11 418authentication protocol and cookie (if applicable) in standard input. 419See 420.Sx SSHRC , 421below. 422.It 423Runs user's shell or command. 424All commands are run under the user's login shell as specified in the 425system password database. 426.El 427.Sh SSHRC 428If the file 429.Pa ~/.ssh/rc 430exists, 431.Xr sh 1 432runs it after reading the 433environment files but before starting the user's shell or command. 434It must not produce any output on stdout; stderr must be used 435instead. 436If X11 forwarding is in use, it will receive the "proto cookie" pair in 437its standard input (and 438.Ev DISPLAY 439in its environment). 440The script must call 441.Xr xauth 1 442because 443.Nm 444will not run xauth automatically to add X11 cookies. 445.Pp 446The primary purpose of this file is to run any initialization routines 447which may be needed before the user's home directory becomes 448accessible; AFS is a particular example of such an environment. 449.Pp 450This file will probably contain some initialization code followed by 451something similar to: 452.Bd -literal -offset 3n 453if read proto cookie && [ -n "$DISPLAY" ]; then 454 if [ `echo $DISPLAY | cut -c1-10` = 'localhost:' ]; then 455 # X11UseLocalhost=yes 456 echo add unix:`echo $DISPLAY | 457 cut -c11-` $proto $cookie 458 else 459 # X11UseLocalhost=no 460 echo add $DISPLAY $proto $cookie 461 fi | xauth -q - 462fi 463.Ed 464.Pp 465If this file does not exist, 466.Pa /etc/ssh/sshrc 467is run, and if that 468does not exist either, xauth is used to add the cookie. 469.Sh AUTHORIZED_KEYS FILE FORMAT 470.Cm AuthorizedKeysFile 471specifies the files containing public keys for 472public key authentication; 473if this option is not specified, the default is 474.Pa ~/.ssh/authorized_keys 475and 476.Pa ~/.ssh/authorized_keys2 . 477Each line of the file contains one 478key (empty lines and lines starting with a 479.Ql # 480are ignored as 481comments). 482Protocol 1 public keys consist of the following space-separated fields: 483options, bits, exponent, modulus, comment. 484Protocol 2 public key consist of: 485options, keytype, base64-encoded key, comment. 486The options field is optional; 487its presence is determined by whether the line starts 488with a number or not (the options field never starts with a number). 489The bits, exponent, modulus, and comment fields give the RSA key for 490protocol version 1; the 491comment field is not used for anything (but may be convenient for the 492user to identify the key). 493For protocol version 2 the keytype is 494.Dq ecdsa-sha2-nistp256 , 495.Dq ecdsa-sha2-nistp384 , 496.Dq ecdsa-sha2-nistp521 , 497.Dq ssh-ed25519 , 498.Dq ssh-dss 499or 500.Dq ssh-rsa . 501.Pp 502Note that lines in this file are usually several hundred bytes long 503(because of the size of the public key encoding) up to a limit of 5048 kilobytes, which permits DSA keys up to 8 kilobits and RSA 505keys up to 16 kilobits. 506You don't want to type them in; instead, copy the 507.Pa identity.pub , 508.Pa id_dsa.pub , 509.Pa id_ecdsa.pub , 510.Pa id_ed25519.pub , 511or the 512.Pa id_rsa.pub 513file and edit it. 514.Pp 515.Nm 516enforces a minimum RSA key modulus size for protocol 1 517and protocol 2 keys of 768 bits. 518.Pp 519The options (if present) consist of comma-separated option 520specifications. 521No spaces are permitted, except within double quotes. 522The following option specifications are supported (note 523that option keywords are case-insensitive): 524.Bl -tag -width Ds 525.It Cm agent-forwarding 526Enable authentication agent forwarding previously disabled by the 527.Cm restrict 528option. 529.It Cm cert-authority 530Specifies that the listed key is a certification authority (CA) that is 531trusted to validate signed certificates for user authentication. 532.Pp 533Certificates may encode access restrictions similar to these key options. 534If both certificate restrictions and key options are present, the most 535restrictive union of the two is applied. 536.It Cm command="command" 537Specifies that the command is executed whenever this key is used for 538authentication. 539The command supplied by the user (if any) is ignored. 540The command is run on a pty if the client requests a pty; 541otherwise it is run without a tty. 542If an 8-bit clean channel is required, 543one must not request a pty or should specify 544.Cm no-pty . 545A quote may be included in the command by quoting it with a backslash. 546This option might be useful 547to restrict certain public keys to perform just a specific operation. 548An example might be a key that permits remote backups but nothing else. 549Note that the client may specify TCP and/or X11 550forwarding unless they are explicitly prohibited. 551The command originally supplied by the client is available in the 552.Ev SSH_ORIGINAL_COMMAND 553environment variable. 554Note that this option applies to shell, command or subsystem execution. 555Also note that this command may be superseded by either a 556.Xr sshd_config 5 557.Cm ForceCommand 558directive or a command embedded in a certificate. 559.It Cm environment="NAME=value" 560Specifies that the string is to be added to the environment when 561logging in using this key. 562Environment variables set this way 563override other default environment values. 564Multiple options of this type are permitted. 565Environment processing is disabled by default and is 566controlled via the 567.Cm PermitUserEnvironment 568option. 569This option is automatically disabled if 570.Cm UseLogin 571is enabled. 572.It Cm from="pattern-list" 573Specifies that in addition to public key authentication, either the canonical 574name of the remote host or its IP address must be present in the 575comma-separated list of patterns. 576See PATTERNS in 577.Xr ssh_config 5 578for more information on patterns. 579.Pp 580In addition to the wildcard matching that may be applied to hostnames or 581addresses, a 582.Cm from 583stanza may match IP addresses using CIDR address/masklen notation. 584.Pp 585The purpose of this option is to optionally increase security: public key 586authentication by itself does not trust the network or name servers or 587anything (but the key); however, if somebody somehow steals the key, the key 588permits an intruder to log in from anywhere in the world. 589This additional option makes using a stolen key more difficult (name 590servers and/or routers would have to be compromised in addition to 591just the key). 592.It Cm no-agent-forwarding 593Forbids authentication agent forwarding when this key is used for 594authentication. 595.It Cm no-port-forwarding 596Forbids TCP forwarding when this key is used for authentication. 597Any port forward requests by the client will return an error. 598This might be used, e.g. in connection with the 599.Cm command 600option. 601.It Cm no-pty 602Prevents tty allocation (a request to allocate a pty will fail). 603.It Cm no-user-rc 604Disables execution of 605.Pa ~/.ssh/rc . 606.It Cm no-X11-forwarding 607Forbids X11 forwarding when this key is used for authentication. 608Any X11 forward requests by the client will return an error. 609.It Cm permitopen="host:port" 610Limit local port forwarding with 611.Xr ssh 1 612.Fl L 613such that it may only connect to the specified host and port. 614IPv6 addresses can be specified by enclosing the address in square brackets. 615Multiple 616.Cm permitopen 617options may be applied separated by commas. 618No pattern matching is performed on the specified hostnames, 619they must be literal domains or addresses. 620A port specification of 621.Cm * 622matches any port. 623.It Cm port-forwarding 624Enable port forwarding previously disabled by the 625.Cm restrict 626.It Cm principals="principals" 627On a 628.Cm cert-authority 629line, specifies allowed principals for certificate authentication as a 630comma-separated list. 631At least one name from the list must appear in the certificate's 632list of principals for the certificate to be accepted. 633This option is ignored for keys that are not marked as trusted certificate 634signers using the 635.Cm cert-authority 636option. 637.It Cm pty 638Permits tty allocation previously disabled by the 639.Cm restrict 640option. 641.It Cm restrict 642Enable all restrictions, i.e. disable port, agent and X11 forwarding, 643as well as disabling PTY allocation 644and execution of 645.Pa ~/.ssh/rc . 646If any future restriction capabilities are added to authorized_keys files 647they will be included in this set. 648.It Cm tunnel="n" 649Force a 650.Xr tun 4 651device on the server. 652Without this option, the next available device will be used if 653the client requests a tunnel. 654.It Cm user-rc 655Enables execution of 656.Pa ~/.ssh/rc 657previously disabled by the 658.Cm restrict 659option. 660.It Cm X11-forwarding 661Permits X11 forwarding previously disabled by the 662.Cm restrict 663option. 664.El 665.Pp 666An example authorized_keys file: 667.Bd -literal -offset 3n 668# Comments allowed at start of line 669ssh-rsa AAAAB3Nza...LiPk== user@example.net 670from="*.sales.example.net,!pc.sales.example.net" ssh-rsa 671AAAAB2...19Q== john@example.net 672command="dump /home",no-pty,no-port-forwarding ssh-dss 673AAAAC3...51R== example.net 674permitopen="192.0.2.1:80",permitopen="192.0.2.2:25" ssh-dss 675AAAAB5...21S== 676tunnel="0",command="sh /etc/netstart tun0" ssh-rsa AAAA...== 677jane@example.net 678restrict,command="uptime" ssh-rsa AAAA1C8...32Tv== 679user@example.net 680restrict,pty,command="nethack" ssh-rsa AAAA1f8...IrrC5== 681user@example.net 682.Ed 683.Sh SSH_KNOWN_HOSTS FILE FORMAT 684The 685.Pa /etc/ssh/ssh_known_hosts 686and 687.Pa ~/.ssh/known_hosts 688files contain host public keys for all known hosts. 689The global file should 690be prepared by the administrator (optional), and the per-user file is 691maintained automatically: whenever the user connects from an unknown host, 692its key is added to the per-user file. 693.Pp 694Each line in these files contains the following fields: markers (optional), 695hostnames, bits, exponent, modulus, comment. 696The fields are separated by spaces. 697.Pp 698The marker is optional, but if it is present then it must be one of 699.Dq @cert-authority , 700to indicate that the line contains a certification authority (CA) key, 701or 702.Dq @revoked , 703to indicate that the key contained on the line is revoked and must not ever 704be accepted. 705Only one marker should be used on a key line. 706.Pp 707Hostnames is a comma-separated list of patterns 708.Pf ( Ql * 709and 710.Ql \&? 711act as 712wildcards); each pattern in turn is matched against the canonical host 713name (when authenticating a client) or against the user-supplied 714name (when authenticating a server). 715A pattern may also be preceded by 716.Ql \&! 717to indicate negation: if the host name matches a negated 718pattern, it is not accepted (by that line) even if it matched another 719pattern on the line. 720A hostname or address may optionally be enclosed within 721.Ql \&[ 722and 723.Ql \&] 724brackets then followed by 725.Ql \&: 726and a non-standard port number. 727.Pp 728Alternately, hostnames may be stored in a hashed form which hides host names 729and addresses should the file's contents be disclosed. 730Hashed hostnames start with a 731.Ql | 732character. 733Only one hashed hostname may appear on a single line and none of the above 734negation or wildcard operators may be applied. 735.Pp 736Bits, exponent, and modulus are taken directly from the RSA host key; they 737can be obtained, for example, from 738.Pa /etc/ssh/ssh_host_key.pub . 739The optional comment field continues to the end of the line, and is not used. 740.Pp 741Lines starting with 742.Ql # 743and empty lines are ignored as comments. 744.Pp 745When performing host authentication, authentication is accepted if any 746matching line has the proper key; either one that matches exactly or, 747if the server has presented a certificate for authentication, the key 748of the certification authority that signed the certificate. 749For a key to be trusted as a certification authority, it must use the 750.Dq @cert-authority 751marker described above. 752.Pp 753The known hosts file also provides a facility to mark keys as revoked, 754for example when it is known that the associated private key has been 755stolen. 756Revoked keys are specified by including the 757.Dq @revoked 758marker at the beginning of the key line, and are never accepted for 759authentication or as certification authorities, but instead will 760produce a warning from 761.Xr ssh 1 762when they are encountered. 763.Pp 764It is permissible (but not 765recommended) to have several lines or different host keys for the same 766names. 767This will inevitably happen when short forms of host names 768from different domains are put in the file. 769It is possible 770that the files contain conflicting information; authentication is 771accepted if valid information can be found from either file. 772.Pp 773Note that the lines in these files are typically hundreds of characters 774long, and you definitely don't want to type in the host keys by hand. 775Rather, generate them by a script, 776.Xr ssh-keyscan 1 777or by taking 778.Pa /etc/ssh/ssh_host_key.pub 779and adding the host names at the front. 780.Xr ssh-keygen 1 781also offers some basic automated editing for 782.Pa ~/.ssh/known_hosts 783including removing hosts matching a host name and converting all host 784names to their hashed representations. 785.Pp 786An example ssh_known_hosts file: 787.Bd -literal -offset 3n 788# Comments allowed at start of line 789closenet,...,192.0.2.53 1024 37 159...93 closenet.example.net 790cvs.example.net,192.0.2.10 ssh-rsa AAAA1234.....= 791# A hashed hostname 792|1|JfKTdBh7rNbXkVAQCRp4OQoPfmI=|USECr3SWf1JUPsms5AqfD5QfxkM= ssh-rsa 793AAAA1234.....= 794# A revoked key 795@revoked * ssh-rsa AAAAB5W... 796# A CA key, accepted for any host in *.mydomain.com or *.mydomain.org 797@cert-authority *.mydomain.org,*.mydomain.com ssh-rsa AAAAB5W... 798.Ed 799.Sh FILES 800.Bl -tag -width Ds -compact 801.It Pa ~/.hushlogin 802This file is used to suppress printing the last login time and 803.Pa /etc/motd , 804if 805.Cm PrintLastLog 806and 807.Cm PrintMotd , 808respectively, 809are enabled. 810It does not suppress printing of the banner specified by 811.Cm Banner . 812.Pp 813.It Pa ~/.rhosts 814This file is used for host-based authentication (see 815.Xr ssh 1 816for more information). 817On some machines this file may need to be 818world-readable if the user's home directory is on an NFS partition, 819because 820.Nm 821reads it as root. 822Additionally, this file must be owned by the user, 823and must not have write permissions for anyone else. 824The recommended 825permission for most machines is read/write for the user, and not 826accessible by others. 827.Pp 828.It Pa ~/.shosts 829This file is used in exactly the same way as 830.Pa .rhosts , 831but allows host-based authentication without permitting login with 832rlogin/rsh. 833.Pp 834.It Pa ~/.ssh/ 835This directory is the default location for all user-specific configuration 836and authentication information. 837There is no general requirement to keep the entire contents of this directory 838secret, but the recommended permissions are read/write/execute for the user, 839and not accessible by others. 840.Pp 841.It Pa ~/.ssh/authorized_keys 842Lists the public keys (DSA, ECDSA, Ed25519, RSA) 843that can be used for logging in as this user. 844The format of this file is described above. 845The content of the file is not highly sensitive, but the recommended 846permissions are read/write for the user, and not accessible by others. 847.Pp 848If this file, the 849.Pa ~/.ssh 850directory, or the user's home directory are writable 851by other users, then the file could be modified or replaced by unauthorized 852users. 853In this case, 854.Nm 855will not allow it to be used unless the 856.Cm StrictModes 857option has been set to 858.Dq no . 859.Pp 860.It Pa ~/.ssh/environment 861This file is read into the environment at login (if it exists). 862It can only contain empty lines, comment lines (that start with 863.Ql # ) , 864and assignment lines of the form name=value. 865The file should be writable 866only by the user; it need not be readable by anyone else. 867Environment processing is disabled by default and is 868controlled via the 869.Cm PermitUserEnvironment 870option. 871.Pp 872.It Pa ~/.ssh/known_hosts 873Contains a list of host keys for all hosts the user has logged into 874that are not already in the systemwide list of known host keys. 875The format of this file is described above. 876This file should be writable only by root/the owner and 877can, but need not be, world-readable. 878.Pp 879.It Pa ~/.ssh/rc 880Contains initialization routines to be run before 881the user's home directory becomes accessible. 882This file should be writable only by the user, and need not be 883readable by anyone else. 884.Pp 885.It Pa /etc/hosts.equiv 886This file is for host-based authentication (see 887.Xr ssh 1 ) . 888It should only be writable by root. 889.Pp 890.It Pa /etc/ssh/moduli 891Contains Diffie-Hellman groups used for the "Diffie-Hellman Group Exchange" 892key exchange method. 893The file format is described in 894.Xr moduli 5 . 895If no usable groups are found in this file then fixed internal groups will 896be used. 897.Pp 898.It Pa /etc/motd 899See 900.Xr motd 5 . 901.Pp 902.It Pa /etc/nologin 903If this file exists, 904.Nm 905refuses to let anyone except root log in. 906The contents of the file 907are displayed to anyone trying to log in, and non-root connections are 908refused. 909The file should be world-readable. 910.Pp 911.It Pa /etc/ssh/shosts.equiv 912This file is used in exactly the same way as 913.Pa hosts.equiv , 914but allows host-based authentication without permitting login with 915rlogin/rsh. 916.Pp 917.It Pa /etc/ssh/ssh_host_key 918.It Pa /etc/ssh/ssh_host_dsa_key 919.It Pa /etc/ssh/ssh_host_ecdsa_key 920.It Pa /etc/ssh/ssh_host_ed25519_key 921.It Pa /etc/ssh/ssh_host_rsa_key 922These files contain the private parts of the host keys. 923These files should only be owned by root, readable only by root, and not 924accessible to others. 925Note that 926.Nm 927does not start if these files are group/world-accessible. 928.Pp 929.It Pa /etc/ssh/ssh_host_key.pub 930.It Pa /etc/ssh/ssh_host_dsa_key.pub 931.It Pa /etc/ssh/ssh_host_ecdsa_key.pub 932.It Pa /etc/ssh/ssh_host_ed25519_key.pub 933.It Pa /etc/ssh/ssh_host_rsa_key.pub 934These files contain the public parts of the host keys. 935These files should be world-readable but writable only by 936root. 937Their contents should match the respective private parts. 938These files are not 939really used for anything; they are provided for the convenience of 940the user so their contents can be copied to known hosts files. 941These files are created using 942.Xr ssh-keygen 1 . 943.Pp 944.It Pa /etc/ssh/ssh_known_hosts 945Systemwide list of known host keys. 946This file should be prepared by the 947system administrator to contain the public host keys of all machines in the 948organization. 949The format of this file is described above. 950This file should be writable only by root/the owner and 951should be world-readable. 952.Pp 953.It Pa /etc/ssh/sshd_config 954Contains configuration data for 955.Nm sshd . 956The file format and configuration options are described in 957.Xr sshd_config 5 . 958.Pp 959.It Pa /etc/ssh/sshrc 960Similar to 961.Pa ~/.ssh/rc , 962it can be used to specify 963machine-specific login-time initializations globally. 964This file should be writable only by root, and should be world-readable. 965.Pp 966.It Pa /var/empty 967.Xr chroot 2 968directory used by 969.Nm 970during privilege separation in the pre-authentication phase. 971The directory should not contain any files and must be owned by root 972and not group or world-writable. 973.Pp 974.It Pa /var/run/sshd.pid 975Contains the process ID of the 976.Nm 977listening for connections (if there are several daemons running 978concurrently for different ports, this contains the process ID of the one 979started last). 980The content of this file is not sensitive; it can be world-readable. 981.El 982.Sh SEE ALSO 983.Xr scp 1 , 984.Xr sftp 1 , 985.Xr ssh 1 , 986.Xr ssh-add 1 , 987.Xr ssh-agent 1 , 988.Xr ssh-keygen 1 , 989.Xr ssh-keyscan 1 , 990.Xr chroot 2 , 991.Xr login.conf 5 , 992.Xr moduli 5 , 993.Xr sshd_config 5 , 994.Xr inetd 8 , 995.Xr sftp-server 8 996.Sh AUTHORS 997OpenSSH is a derivative of the original and free 998ssh 1.2.12 release by Tatu Ylonen. 999Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, 1000Theo de Raadt and Dug Song 1001removed many bugs, re-added newer features and 1002created OpenSSH. 1003Markus Friedl contributed the support for SSH 1004protocol versions 1.5 and 2.0. 1005Niels Provos and Markus Friedl contributed support 1006for privilege separation. 1007