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