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