sshd.0 revision 180744
1238710SadrianSSHD(8) OpenBSD System Manager's Manual SSHD(8) 2238710Sadrian 3238710SadrianNAME 4238710Sadrian sshd - OpenSSH SSH daemon 5238710Sadrian 6238710SadrianSYNOPSIS 7238710Sadrian sshd [-46Ddeiqt] [-b bits] [-f config_file] [-g login_grace_time] 8238710Sadrian [-h host_key_file] [-k key_gen_time] [-o option] [-p port] [-u len] 9238710Sadrian 10238710SadrianDESCRIPTION 11238710Sadrian sshd (OpenSSH Daemon) is the daemon program for ssh(1). Together these 12238710Sadrian programs replace rlogin(1) and rsh(1), and provide secure encrypted com- 13238710Sadrian munications between two untrusted hosts over an insecure network. 14238710Sadrian 15238710Sadrian sshd listens for connections from clients. It is normally started at 16238710Sadrian boot from /etc/rc. It forks a new daemon for each incoming connection. 17238710Sadrian The forked daemons handle key exchange, encryption, authentication, com- 18238710Sadrian mand execution, and data exchange. 19238710Sadrian 20238710Sadrian sshd can be configured using command-line options or a configuration file 21238710Sadrian (by default sshd_config(5)); command-line options override values speci- 22238710Sadrian fied in the configuration file. sshd rereads its configuration file when 23238710Sadrian it receives a hangup signal, SIGHUP, by executing itself with the name 24238710Sadrian and options it was started with, e.g. /usr/sbin/sshd. 25238710Sadrian 26238710Sadrian The options are as follows: 27238710Sadrian 28238710Sadrian -4 Forces sshd to use IPv4 addresses only. 29238710Sadrian 30238710Sadrian -6 Forces sshd to use IPv6 addresses only. 31238710Sadrian 32238710Sadrian -b bits 33238710Sadrian Specifies the number of bits in the ephemeral protocol version 1 34238710Sadrian server key (default 768). 35238710Sadrian 36238710Sadrian -D When this option is specified, sshd will not detach and does not 37 become a daemon. This allows easy monitoring of sshd. 38 39 -d Debug mode. The server sends verbose debug output to the system 40 log, and does not put itself in the background. The server also 41 will not fork and will only process one connection. This option 42 is only intended for debugging for the server. Multiple -d op- 43 tions increase the debugging level. Maximum is 3. 44 45 -e When this option is specified, sshd will send the output to the 46 standard error instead of the system log. 47 48 -f config_file 49 Specifies the name of the configuration file. The default is 50 /etc/ssh/sshd_config. sshd refuses to start if there is no con- 51 figuration file. 52 53 -g login_grace_time 54 Gives the grace time for clients to authenticate themselves (de- 55 fault 120 seconds). If the client fails to authenticate the user 56 within this many seconds, the server disconnects and exits. A 57 value of zero indicates no limit. 58 59 -h host_key_file 60 Specifies a file from which a host key is read. This option must 61 be given if sshd is not run as root (as the normal host key files 62 are normally not readable by anyone but root). The default is 63 /etc/ssh/ssh_host_key for protocol version 1, and 64 /etc/ssh/ssh_host_rsa_key and /etc/ssh/ssh_host_dsa_key for pro- 65 tocol version 2. It is possible to have multiple host key files 66 for the different protocol versions and host key algorithms. 67 68 -i Specifies that sshd is being run from inetd(8). sshd is normally 69 not run from inetd because it needs to generate the server key 70 before it can respond to the client, and this may take tens of 71 seconds. Clients would have to wait too long if the key was re- 72 generated every time. However, with small key sizes (e.g. 512) 73 using sshd from inetd may be feasible. 74 75 -k key_gen_time 76 Specifies how often the ephemeral protocol version 1 server key 77 is regenerated (default 3600 seconds, or one hour). The motiva- 78 tion for regenerating the key fairly often is that the key is not 79 stored anywhere, and after about an hour it becomes impossible to 80 recover the key for decrypting intercepted communications even if 81 the machine is cracked into or physically seized. A value of ze- 82 ro indicates that the key will never be regenerated. 83 84 -o option 85 Can be used to give options in the format used in the configura- 86 tion file. This is useful for specifying options for which there 87 is no separate command-line flag. For full details of the op- 88 tions, and their values, see sshd_config(5). 89 90 -p port 91 Specifies the port on which the server listens for connections 92 (default 22). Multiple port options are permitted. Ports speci- 93 fied in the configuration file with the Port option are ignored 94 when a command-line port is specified. Ports specified using the 95 ListenAddress option override command-line ports. 96 97 -q Quiet mode. Nothing is sent to the system log. Normally the be- 98 ginning, authentication, and termination of each connection is 99 logged. 100 101 -t Test mode. Only check the validity of the configuration file and 102 sanity of the keys. This is useful for updating sshd reliably as 103 configuration options may change. 104 105 -u len This option is used to specify the size of the field in the utmp 106 structure that holds the remote host name. If the resolved host 107 name is longer than len, the dotted decimal value will be used 108 instead. This allows hosts with very long host names that over- 109 flow this field to still be uniquely identified. Specifying -u0 110 indicates that only dotted decimal addresses should be put into 111 the utmp file. -u0 may also be used to prevent sshd from making 112 DNS requests unless the authentication mechanism or configuration 113 requires it. Authentication mechanisms that may require DNS in- 114 clude RhostsRSAAuthentication, HostbasedAuthentication, and using 115 a from="pattern-list" option in a key file. Configuration op- 116 tions that require DNS include using a USER@HOST pattern in 117 AllowUsers or DenyUsers. 118 119AUTHENTICATION 120 The OpenSSH SSH daemon supports SSH protocols 1 and 2. Both protocols 121 are supported by default, though this can be changed via the Protocol op- 122 tion in sshd_config(5). Protocol 2 supports both RSA and DSA keys; pro- 123 tocol 1 only supports RSA keys. For both protocols, each host has a 124 host-specific key, normally 2048 bits, used to identify the host. 125 126 Forward security for protocol 1 is provided through an additional server 127 key, normally 768 bits, generated when the server starts. This key is 128 normally regenerated every hour if it has been used, and is never stored 129 on disk. Whenever a client connects, the daemon responds with its public 130 host and server keys. The client compares the RSA host key against its 131 own database to verify that it has not changed. The client then gener- 132 ates a 256-bit random number. It encrypts this random number using both 133 the host key and the server key, and sends the encrypted number to the 134 server. Both sides then use this random number as a session key which is 135 used to encrypt all further communications in the session. The rest of 136 the session is encrypted using a conventional cipher, currently Blowfish 137 or 3DES, with 3DES being used by default. The client selects the encryp- 138 tion algorithm to use from those offered by the server. 139 140 For protocol 2, forward security is provided through a Diffie-Hellman key 141 agreement. This key agreement results in a shared session key. The rest 142 of the session is encrypted using a symmetric cipher, currently 128-bit 143 AES, Blowfish, 3DES, CAST128, Arcfour, 192-bit AES, or 256-bit AES. The 144 client selects the encryption algorithm to use from those offered by the 145 server. Additionally, session integrity is provided through a crypto- 146 graphic message authentication code (hmac-md5, hmac-sha1, umac-64 or 147 hmac-ripemd160). 148 149 Finally, the server and the client enter an authentication dialog. The 150 client tries to authenticate itself using host-based authentication, pub- 151 lic key authentication, challenge-response authentication, or password 152 authentication. 153 154 Regardless of the authentication type, the account is checked to ensure 155 that it is accessible. An account is not accessible if it is locked, 156 listed in DenyUsers or its group is listed in DenyGroups . The defini- 157 tion of a locked account is system dependant. Some platforms have their 158 own account database (eg AIX) and some modify the passwd field ( `*LK*' 159 on Solaris and UnixWare, `*' on HP-UX, containing `Nologin' on Tru64, a 160 leading `*LOCKED*' on FreeBSD and a leading `!' on most Linuxes). If 161 there is a requirement to disable password authentication for the account 162 while allowing still public-key, then the passwd field should be set to 163 something other than these values (eg `NP' or `*NP*' ). 164 165 If the client successfully authenticates itself, a dialog for preparing 166 the session is entered. At this time the client may request things like 167 allocating a pseudo-tty, forwarding X11 connections, forwarding TCP con- 168 nections, or forwarding the authentication agent connection over the se- 169 cure channel. 170 171 After this, the client either requests a shell or execution of a command. 172 The sides then enter session mode. In this mode, either side may send 173 data at any time, and such data is forwarded to/from the shell or command 174 on the server side, and the user terminal in the client side. 175 176 When the user program terminates and all forwarded X11 and other connec- 177 tions have been closed, the server sends command exit status to the 178 client, and both sides exit. 179 180LOGIN PROCESS 181 When a user successfully logs in, sshd does the following: 182 183 1. If the login is on a tty, and no command has been specified, 184 prints last login time and /etc/motd (unless prevented in the 185 configuration file or by ~/.hushlogin; see the FILES section). 186 187 2. If the login is on a tty, records login time. 188 189 3. Checks /etc/nologin; if it exists, prints contents and quits 190 (unless root). 191 192 4. Changes to run with normal user privileges. 193 194 5. Sets up basic environment. 195 196 6. Reads the file ~/.ssh/environment, if it exists, and users are 197 allowed to change their environment. See the 198 PermitUserEnvironment option in sshd_config(5). 199 200 7. Changes to user's home directory. 201 202 8. If ~/.ssh/rc exists, runs it; else if /etc/ssh/sshrc exists, 203 runs it; otherwise runs xauth. The ``rc'' files are given the 204 X11 authentication protocol and cookie in standard input. See 205 SSHRC, below. 206 207 9. Runs user's shell or command. 208 209SSHRC 210 If the file ~/.ssh/rc exists, sh(1) runs it after reading the environment 211 files but before starting the user's shell or command. It must not pro- 212 duce any output on stdout; stderr must be used instead. If X11 forward- 213 ing is in use, it will receive the "proto cookie" pair in its standard 214 input (and DISPLAY in its environment). The script must call xauth(1) 215 because sshd will not run xauth automatically to add X11 cookies. 216 217 The primary purpose of this file is to run any initialization routines 218 which may be needed before the user's home directory becomes accessible; 219 AFS is a particular example of such an environment. 220 221 This file will probably contain some initialization code followed by 222 something similar to: 223 224 if read proto cookie && [ -n "$DISPLAY" ]; then 225 if [ `echo $DISPLAY | cut -c1-10` = 'localhost:' ]; then 226 # X11UseLocalhost=yes 227 echo add unix:`echo $DISPLAY | 228 cut -c11-` $proto $cookie 229 else 230 # X11UseLocalhost=no 231 echo add $DISPLAY $proto $cookie 232 fi | xauth -q - 233 fi 234 235 If this file does not exist, /etc/ssh/sshrc is run, and if that does not 236 exist either, xauth is used to add the cookie. 237 238AUTHORIZED_KEYS FILE FORMAT 239 AuthorizedKeysFile specifies the file containing public keys for public 240 key authentication; if none is specified, the default is 241 ~/.ssh/authorized_keys. Each line of the file contains one key (empty 242 lines and lines starting with a `#' are ignored as comments). Protocol 1 243 public keys consist of the following space-separated fields: options, 244 bits, exponent, modulus, comment. Protocol 2 public key consist of: op- 245 tions, keytype, base64-encoded key, comment. The options field is op- 246 tional; its presence is determined by whether the line starts with a num- 247 ber or not (the options field never starts with a number). The bits, ex- 248 ponent, modulus, and comment fields give the RSA key for protocol version 249 1; the comment field is not used for anything (but may be convenient for 250 the user to identify the key). For protocol version 2 the keytype is 251 ``ssh-dss'' or ``ssh-rsa''. 252 253 Note that lines in this file are usually several hundred bytes long (be- 254 cause of the size of the public key encoding) up to a limit of 8 kilo- 255 bytes, which permits DSA keys up to 8 kilobits and RSA keys up to 16 256 kilobits. You don't want to type them in; instead, copy the 257 identity.pub, id_dsa.pub, or the id_rsa.pub file and edit it. 258 259 sshd enforces a minimum RSA key modulus size for protocol 1 and protocol 260 2 keys of 768 bits. 261 262 The options (if present) consist of comma-separated option specifica- 263 tions. No spaces are permitted, except within double quotes. The fol- 264 lowing option specifications are supported (note that option keywords are 265 case-insensitive): 266 267 command="command" 268 Specifies that the command is executed whenever this key is used 269 for authentication. The command supplied by the user (if any) is 270 ignored. The command is run on a pty if the client requests a 271 pty; otherwise it is run without a tty. If an 8-bit clean chan- 272 nel is required, one must not request a pty or should specify no- 273 pty. A quote may be included in the command by quoting it with a 274 backslash. This option might be useful to restrict certain pub- 275 lic keys to perform just a specific operation. An example might 276 be a key that permits remote backups but nothing else. Note that 277 the client may specify TCP and/or X11 forwarding unless they are 278 explicitly prohibited. The command originally supplied by the 279 client is available in the SSH_ORIGINAL_COMMAND environment vari- 280 able. Note that this option applies to shell, command or subsys- 281 tem execution. 282 283 environment="NAME=value" 284 Specifies that the string is to be added to the environment when 285 logging in using this key. Environment variables set this way 286 override other default environment values. Multiple options of 287 this type are permitted. Environment processing is disabled by 288 default and is controlled via the PermitUserEnvironment option. 289 This option is automatically disabled if UseLogin is enabled. 290 291 from="pattern-list" 292 Specifies that in addition to public key authentication, the 293 canonical name of the remote host must be present in the comma- 294 separated list of patterns. The purpose of this option is to op- 295 tionally increase security: public key authentication by itself 296 does not trust the network or name servers or anything (but the 297 key); however, if somebody somehow steals the key, the key per- 298 mits an intruder to log in from anywhere in the world. This ad- 299 ditional option makes using a stolen key more difficult (name 300 servers and/or routers would have to be compromised in addition 301 to just the key). 302 303 See PATTERNS in ssh_config(5) for more information on patterns. 304 305 no-agent-forwarding 306 Forbids authentication agent forwarding when this key is used for 307 authentication. 308 309 no-port-forwarding 310 Forbids TCP forwarding when this key is used for authentication. 311 Any port forward requests by the client will return an error. 312 This might be used, e.g. in connection with the command option. 313 314 no-pty Prevents tty allocation (a request to allocate a pty will fail). 315 316 no-X11-forwarding 317 Forbids X11 forwarding when this key is used for authentication. 318 Any X11 forward requests by the client will return an error. 319 320 permitopen="host:port" 321 Limit local ``ssh -L'' port forwarding such that it may only con- 322 nect to the specified host and port. IPv6 addresses can be spec- 323 ified with an alternative syntax: host/port. Multiple permitopen 324 options may be applied separated by commas. No pattern matching 325 is performed on the specified hostnames, they must be literal do- 326 mains or addresses. 327 328 tunnel="n" 329 Force a tun(4) device on the server. Without this option, the 330 next available device will be used if the client requests a tun- 331 nel. 332 333 An example authorized_keys file: 334 335 # Comments allowed at start of line 336 ssh-rsa AAAAB3Nza...LiPk== user@example.net 337 from="*.sales.example.net,!pc.sales.example.net" ssh-rsa 338 AAAAB2...19Q== john@example.net 339 command="dump /home",no-pty,no-port-forwarding ssh-dss 340 AAAAC3...51R== example.net 341 permitopen="192.0.2.1:80",permitopen="192.0.2.2:25" ssh-dss 342 AAAAB5...21S== 343 tunnel="0",command="sh /etc/netstart tun0" ssh-rsa AAAA...== 344 jane@example.net 345 346SSH_KNOWN_HOSTS FILE FORMAT 347 The /etc/ssh/ssh_known_hosts and ~/.ssh/known_hosts files contain host 348 public keys for all known hosts. The global file should be prepared by 349 the administrator (optional), and the per-user file is maintained auto- 350 matically: whenever the user connects from an unknown host, its key is 351 added to the per-user file. 352 353 Each line in these files contains the following fields: hostnames, bits, 354 exponent, modulus, comment. The fields are separated by spaces. 355 356 Hostnames is a comma-separated list of patterns (`*' and `?' act as wild- 357 cards); each pattern in turn is matched against the canonical host name 358 (when authenticating a client) or against the user-supplied name (when 359 authenticating a server). A pattern may also be preceded by `!' to indi- 360 cate negation: if the host name matches a negated pattern, it is not ac- 361 cepted (by that line) even if it matched another pattern on the line. A 362 hostname or address may optionally be enclosed within `[' and `]' brack- 363 ets then followed by `:' and a non-standard port number. 364 365 Alternately, hostnames may be stored in a hashed form which hides host 366 names and addresses should the file's contents be disclosed. Hashed 367 hostnames start with a `|' character. Only one hashed hostname may ap- 368 pear on a single line and none of the above negation or wildcard opera- 369 tors may be applied. 370 371 Bits, exponent, and modulus are taken directly from the RSA host key; 372 they can be obtained, for example, from /etc/ssh/ssh_host_key.pub. The 373 optional comment field continues to the end of the line, and is not used. 374 375 Lines starting with `#' and empty lines are ignored as comments. 376 377 When performing host authentication, authentication is accepted if any 378 matching line has the proper key. It is thus permissible (but not recom- 379 mended) to have several lines or different host keys for the same names. 380 This will inevitably happen when short forms of host names from different 381 domains are put in the file. It is possible that the files contain con- 382 flicting information; authentication is accepted if valid information can 383 be found from either file. 384 385 Note that the lines in these files are typically hundreds of characters 386 long, and you definitely don't want to type in the host keys by hand. 387 Rather, generate them by a script or by taking /etc/ssh/ssh_host_key.pub 388 and adding the host names at the front. 389 390 An example ssh_known_hosts file: 391 392 # Comments allowed at start of line 393 closenet,...,192.0.2.53 1024 37 159...93 closenet.example.net 394 cvs.example.net,192.0.2.10 ssh-rsa AAAA1234.....= 395 # A hashed hostname 396 |1|JfKTdBh7rNbXkVAQCRp4OQoPfmI=|USECr3SWf1JUPsms5AqfD5QfxkM= ssh-rsa 397 AAAA1234.....= 398 399FILES 400 ~/.hushlogin 401 This file is used to suppress printing the last login time and 402 /etc/motd, if PrintLastLog and PrintMotd, respectively, are en- 403 abled. It does not suppress printing of the banner specified by 404 Banner. 405 406 ~/.rhosts 407 This file is used for host-based authentication (see ssh(1) for 408 more information). On some machines this file may need to be 409 world-readable if the user's home directory is on an NFS parti- 410 tion, because sshd reads it as root. Additionally, this file 411 must be owned by the user, and must not have write permissions 412 for anyone else. The recommended permission for most machines is 413 read/write for the user, and not accessible by others. 414 415 ~/.shosts 416 This file is used in exactly the same way as .rhosts, but allows 417 host-based authentication without permitting login with 418 rlogin/rsh. 419 420 ~/.ssh/authorized_keys 421 Lists the public keys (RSA/DSA) that can be used for logging in 422 as this user. The format of this file is described above. The 423 content of the file is not highly sensitive, but the recommended 424 permissions are read/write for the user, and not accessible by 425 others. 426 427 If this file, the ~/.ssh directory, or the user's home directory 428 are writable by other users, then the file could be modified or 429 replaced by unauthorized users. In this case, sshd will not al- 430 low it to be used unless the StrictModes option has been set to 431 ``no''. The recommended permissions can be set by executing 432 ``chmod go-w ~/ ~/.ssh ~/.ssh/authorized_keys''. 433 434 ~/.ssh/environment 435 This file is read into the environment at login (if it exists). 436 It can only contain empty lines, comment lines (that start with 437 `#'), and assignment lines of the form name=value. The file 438 should be writable only by the user; it need not be readable by 439 anyone else. Environment processing is disabled by default and 440 is controlled via the PermitUserEnvironment option. 441 442 ~/.ssh/known_hosts 443 Contains a list of host keys for all hosts the user has logged 444 into that are not already in the systemwide list of known host 445 keys. The format of this file is described above. This file 446 should be writable only by root/the owner and can, but need not 447 be, world-readable. 448 449 ~/.ssh/rc 450 Contains initialization routines to be run before the user's home 451 directory becomes accessible. This file should be writable only 452 by the user, and need not be readable by anyone else. 453 454 /etc/hosts.allow 455 /etc/hosts.deny 456 Access controls that should be enforced by tcp-wrappers are de- 457 fined here. Further details are described in hosts_access(5). 458 459 /etc/hosts.equiv 460 This file is for host-based authentication (see ssh(1)). It 461 should only be writable by root. 462 463 /etc/moduli 464 Contains Diffie-Hellman groups used for the "Diffie-Hellman Group 465 Exchange". The file format is described in moduli(5). 466 467 /etc/motd 468 See motd(5). 469 470 /etc/nologin 471 If this file exists, sshd refuses to let anyone except root log 472 in. The contents of the file are displayed to anyone trying to 473 log in, and non-root connections are refused. The file should be 474 world-readable. 475 476 /etc/shosts.equiv 477 This file is used in exactly the same way as hosts.equiv, but al- 478 lows host-based authentication without permitting login with 479 rlogin/rsh. 480 481 /etc/ssh/ssh_host_key 482 /etc/ssh/ssh_host_dsa_key 483 /etc/ssh/ssh_host_rsa_key 484 These three files contain the private parts of the host keys. 485 These files should only be owned by root, readable only by root, 486 and not accessible to others. Note that sshd does not start if 487 these files are group/world-accessible. 488 489 /etc/ssh/ssh_host_key.pub 490 /etc/ssh/ssh_host_dsa_key.pub 491 /etc/ssh/ssh_host_rsa_key.pub 492 These three files contain the public parts of the host keys. 493 These files should be world-readable but writable only by root. 494 Their contents should match the respective private parts. These 495 files are not really used for anything; they are provided for the 496 convenience of the user so their contents can be copied to known 497 hosts files. These files are created using ssh-keygen(1). 498 499 /etc/ssh/ssh_known_hosts 500 Systemwide list of known host keys. This file should be prepared 501 by the system administrator to contain the public host keys of 502 all machines in the organization. The format of this file is de- 503 scribed above. This file should be writable only by root/the 504 owner and should be world-readable. 505 506 /etc/ssh/sshd_config 507 Contains configuration data for sshd. The file format and con- 508 figuration options are described in sshd_config(5). 509 510 /etc/ssh/sshrc 511 Similar to ~/.ssh/rc, it can be used to specify machine-specific 512 login-time initializations globally. This file should be 513 writable only by root, and should be world-readable. 514 515 /var/empty 516 chroot(2) directory used by sshd during privilege separation in 517 the pre-authentication phase. The directory should not contain 518 any files and must be owned by root and not group or world- 519 writable. 520 521 /var/run/sshd.pid 522 Contains the process ID of the sshd listening for connections (if 523 there are several daemons running concurrently for different 524 ports, this contains the process ID of the one started last). 525 The content of this file is not sensitive; it can be world-read- 526 able. 527 528SEE ALSO 529 scp(1), sftp(1), ssh(1), ssh-add(1), ssh-agent(1), ssh-keygen(1), 530 ssh-keyscan(1), chroot(2), hosts_access(5), login.conf(5), moduli(5), 531 sshd_config(5), inetd(8), sftp-server(8) 532 533AUTHORS 534 OpenSSH is a derivative of the original and free ssh 1.2.12 release by 535 Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo 536 de Raadt and Dug Song removed many bugs, re-added newer features and cre- 537 ated OpenSSH. Markus Friedl contributed the support for SSH protocol 538 versions 1.5 and 2.0. Niels Provos and Markus Friedl contributed support 539 for privilege separation. 540 541CAVEATS 542 System security is not improved unless rshd, rlogind, and rexecd are dis- 543 abled (thus completely disabling rlogin and rsh into the machine). 544 545OpenBSD 4.2 August 16, 2007 9 546