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