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