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