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