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