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