xref: /freebsd/crypto/openssh/ssh.1 (revision aa12cea2ccc6e686d6d31cf67d6bc69cbc1ba744)
1.\"  -*- nroff -*-
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: ssh.1,v 1.302 2010/03/05 10:28:21 djm Exp $
38.\" $FreeBSD$
39.Dd March 5 2010
40.Dt SSH 1
41.Os
42.Sh NAME
43.Nm ssh
44.Nd OpenSSH SSH client (remote login program)
45.Sh SYNOPSIS
46.Nm ssh
47.Op Fl 1246AaCfgKkMNnqsTtVvXxYy
48.Op Fl b Ar bind_address
49.Op Fl c Ar cipher_spec
50.Oo Fl D\ \&
51.Sm off
52.Oo Ar bind_address : Oc
53.Ar port
54.Sm on
55.Oc
56.Op Fl e Ar escape_char
57.Op Fl F Ar configfile
58.Op Fl I Ar pkcs11
59.Bk -words
60.Op Fl i Ar identity_file
61.Ek
62.Oo Fl L\ \&
63.Sm off
64.Oo Ar bind_address : Oc
65.Ar port : host : hostport
66.Sm on
67.Oc
68.Bk -words
69.Op Fl l Ar login_name
70.Ek
71.Op Fl m Ar mac_spec
72.Op Fl O Ar ctl_cmd
73.Op Fl o Ar option
74.Op Fl p Ar port
75.Oo Fl R\ \&
76.Sm off
77.Oo Ar bind_address : Oc
78.Ar port : host : hostport
79.Sm on
80.Oc
81.Op Fl S Ar ctl_path
82.Op Fl W Ar host : Ns Ar port
83.Oo Fl w Ar local_tun Ns
84.Op : Ns Ar remote_tun Oc
85.Oo Ar user Ns @ Oc Ns Ar hostname
86.Op Ar command
87.Sh DESCRIPTION
88.Nm
89(SSH client) is a program for logging into a remote machine and for
90executing commands on a remote machine.
91It is intended to replace rlogin and rsh,
92and provide secure encrypted communications between
93two untrusted hosts over an insecure network.
94X11 connections and arbitrary TCP ports
95can also be forwarded over the secure channel.
96.Pp
97.Nm
98connects and logs into the specified
99.Ar hostname
100(with optional
101.Ar user
102name).
103The user must prove
104his/her identity to the remote machine using one of several methods
105depending on the protocol version used (see below).
106.Pp
107If
108.Ar command
109is specified,
110it is executed on the remote host instead of a login shell.
111.Pp
112The options are as follows:
113.Bl -tag -width Ds
114.It Fl 1
115Forces
116.Nm
117to try protocol version 1 only.
118.It Fl 2
119Forces
120.Nm
121to try protocol version 2 only.
122.It Fl 4
123Forces
124.Nm
125to use IPv4 addresses only.
126.It Fl 6
127Forces
128.Nm
129to use IPv6 addresses only.
130.It Fl A
131Enables forwarding of the authentication agent connection.
132This can also be specified on a per-host basis in a configuration file.
133.Pp
134Agent forwarding should be enabled with caution.
135Users with the ability to bypass file permissions on the remote host
136(for the agent's
137.Ux Ns -domain
138socket) can access the local agent through the forwarded connection.
139An attacker cannot obtain key material from the agent,
140however they can perform operations on the keys that enable them to
141authenticate using the identities loaded into the agent.
142.It Fl a
143Disables forwarding of the authentication agent connection.
144.It Fl b Ar bind_address
145Use
146.Ar bind_address
147on the local machine as the source address
148of the connection.
149Only useful on systems with more than one address.
150.It Fl C
151Requests compression of all data (including stdin, stdout, stderr, and
152data for forwarded X11 and TCP connections).
153The compression algorithm is the same used by
154.Xr gzip 1 ,
155and the
156.Dq level
157can be controlled by the
158.Cm CompressionLevel
159option for protocol version 1.
160Compression is desirable on modem lines and other
161slow connections, but will only slow down things on fast networks.
162The default value can be set on a host-by-host basis in the
163configuration files; see the
164.Cm Compression
165option.
166.It Fl c Ar cipher_spec
167Selects the cipher specification for encrypting the session.
168.Pp
169Protocol version 1 allows specification of a single cipher.
170The supported values are
171.Dq 3des ,
172.Dq blowfish ,
173and
174.Dq des .
175.Ar 3des
176(triple-des) is an encrypt-decrypt-encrypt triple with three different keys.
177It is believed to be secure.
178.Ar blowfish
179is a fast block cipher; it appears very secure and is much faster than
180.Ar 3des .
181.Ar des
182is only supported in the
183.Nm
184client for interoperability with legacy protocol 1 implementations
185that do not support the
186.Ar 3des
187cipher.
188Its use is strongly discouraged due to cryptographic weaknesses.
189The default is
190.Dq 3des .
191.Pp
192For protocol version 2,
193.Ar cipher_spec
194is a comma-separated list of ciphers
195listed in order of preference.
196See the
197.Cm Ciphers
198keyword for more information.
199.It Fl D Xo
200.Sm off
201.Oo Ar bind_address : Oc
202.Ar port
203.Sm on
204.Xc
205Specifies a local
206.Dq dynamic
207application-level port forwarding.
208This works by allocating a socket to listen to
209.Ar port
210on the local side, optionally bound to the specified
211.Ar bind_address .
212Whenever a connection is made to this port, the
213connection is forwarded over the secure channel, and the application
214protocol is then used to determine where to connect to from the
215remote machine.
216Currently the SOCKS4 and SOCKS5 protocols are supported, and
217.Nm
218will act as a SOCKS server.
219Only root can forward privileged ports.
220Dynamic port forwardings can also be specified in the configuration file.
221.Pp
222IPv6 addresses can be specified with an alternative syntax:
223.Sm off
224.Xo
225.Op Ar bind_address No /
226.Ar port
227.Xc
228.Sm on
229or by enclosing the address in square brackets.
230Only the superuser can forward privileged ports.
231By default, the local port is bound in accordance with the
232.Cm GatewayPorts
233setting.
234However, an explicit
235.Ar bind_address
236may be used to bind the connection to a specific address.
237The
238.Ar bind_address
239of
240.Dq localhost
241indicates that the listening port be bound for local use only, while an
242empty address or
243.Sq *
244indicates that the port should be available from all interfaces.
245.It Fl e Ar escape_char
246Sets the escape character for sessions with a pty (default:
247.Ql ~ ) .
248The escape character is only recognized at the beginning of a line.
249The escape character followed by a dot
250.Pq Ql \&.
251closes the connection;
252followed by control-Z suspends the connection;
253and followed by itself sends the escape character once.
254Setting the character to
255.Dq none
256disables any escapes and makes the session fully transparent.
257.It Fl F Ar configfile
258Specifies an alternative per-user configuration file.
259If a configuration file is given on the command line,
260the system-wide configuration file
261.Pq Pa /etc/ssh/ssh_config
262will be ignored.
263The default for the per-user configuration file is
264.Pa ~/.ssh/config .
265.It Fl f
266Requests
267.Nm
268to go to background just before command execution.
269This is useful if
270.Nm
271is going to ask for passwords or passphrases, but the user
272wants it in the background.
273This implies
274.Fl n .
275The recommended way to start X11 programs at a remote site is with
276something like
277.Ic ssh -f host xterm .
278.Pp
279If the
280.Cm ExitOnForwardFailure
281configuration option is set to
282.Dq yes ,
283then a client started with
284.Fl f
285will wait for all remote port forwards to be successfully established
286before placing itself in the background.
287.It Fl g
288Allows remote hosts to connect to local forwarded ports.
289.It Fl I Ar pkcs11
290Specify the PKCS#11 shared library
291.Nm
292should use to communicate with a PKCS#11 token providing the user's
293private RSA key.
294.It Fl i Ar identity_file
295Selects a file from which the identity (private key) for
296RSA or DSA authentication is read.
297The default is
298.Pa ~/.ssh/identity
299for protocol version 1, and
300.Pa ~/.ssh/id_rsa
301and
302.Pa ~/.ssh/id_dsa
303for protocol version 2.
304Identity files may also be specified on
305a per-host basis in the configuration file.
306It is possible to have multiple
307.Fl i
308options (and multiple identities specified in
309configuration files).
310.Nm
311will also try to load certificate information from the filename obtained
312by appending
313.Pa -cert.pub
314to identity filenames.
315.It Fl K
316Enables GSSAPI-based authentication and forwarding (delegation) of GSSAPI
317credentials to the server.
318.It Fl k
319Disables forwarding (delegation) of GSSAPI credentials to the server.
320.It Fl L Xo
321.Sm off
322.Oo Ar bind_address : Oc
323.Ar port : host : hostport
324.Sm on
325.Xc
326Specifies that the given port on the local (client) host is to be
327forwarded to the given host and port on the remote side.
328This works by allocating a socket to listen to
329.Ar port
330on the local side, optionally bound to the specified
331.Ar bind_address .
332Whenever a connection is made to this port, the
333connection is forwarded over the secure channel, and a connection is
334made to
335.Ar host
336port
337.Ar hostport
338from the remote machine.
339Port forwardings can also be specified in the configuration file.
340IPv6 addresses can be specified with an alternative syntax:
341.Sm off
342.Xo
343.Op Ar bind_address No /
344.Ar port No / Ar host No /
345.Ar hostport
346.Xc
347.Sm on
348or by enclosing the address in square brackets.
349Only the superuser can forward privileged ports.
350By default, the local port is bound in accordance with the
351.Cm GatewayPorts
352setting.
353However, an explicit
354.Ar bind_address
355may be used to bind the connection to a specific address.
356The
357.Ar bind_address
358of
359.Dq localhost
360indicates that the listening port be bound for local use only, while an
361empty address or
362.Sq *
363indicates that the port should be available from all interfaces.
364.It Fl l Ar login_name
365Specifies the user to log in as on the remote machine.
366This also may be specified on a per-host basis in the configuration file.
367.It Fl M
368Places the
369.Nm
370client into
371.Dq master
372mode for connection sharing.
373Multiple
374.Fl M
375options places
376.Nm
377into
378.Dq master
379mode with confirmation required before slave connections are accepted.
380Refer to the description of
381.Cm ControlMaster
382in
383.Xr ssh_config 5
384for details.
385.It Fl m Ar mac_spec
386Additionally, for protocol version 2 a comma-separated list of MAC
387(message authentication code) algorithms can
388be specified in order of preference.
389See the
390.Cm MACs
391keyword for more information.
392.It Fl N
393Do not execute a remote command.
394This is useful for just forwarding ports
395(protocol version 2 only).
396.It Fl n
397Redirects stdin from
398.Pa /dev/null
399(actually, prevents reading from stdin).
400This must be used when
401.Nm
402is run in the background.
403A common trick is to use this to run X11 programs on a remote machine.
404For example,
405.Ic ssh -n shadows.cs.hut.fi emacs &
406will start an emacs on shadows.cs.hut.fi, and the X11
407connection will be automatically forwarded over an encrypted channel.
408The
409.Nm
410program will be put in the background.
411(This does not work if
412.Nm
413needs to ask for a password or passphrase; see also the
414.Fl f
415option.)
416.It Fl O Ar ctl_cmd
417Control an active connection multiplexing master process.
418When the
419.Fl O
420option is specified, the
421.Ar ctl_cmd
422argument is interpreted and passed to the master process.
423Valid commands are:
424.Dq check
425(check that the master process is running) and
426.Dq exit
427(request the master to exit).
428.It Fl o Ar option
429Can be used to give options in the format used in the configuration file.
430This is useful for specifying options for which there is no separate
431command-line flag.
432For full details of the options listed below, and their possible values, see
433.Xr ssh_config 5 .
434.Pp
435.Bl -tag -width Ds -offset indent -compact
436.It AddressFamily
437.It BatchMode
438.It BindAddress
439.It ChallengeResponseAuthentication
440.It CheckHostIP
441.It Cipher
442.It Ciphers
443.It ClearAllForwardings
444.It Compression
445.It CompressionLevel
446.It ConnectionAttempts
447.It ConnectTimeout
448.It ControlMaster
449.It ControlPath
450.It DynamicForward
451.It EscapeChar
452.It ExitOnForwardFailure
453.It ForwardAgent
454.It ForwardX11
455.It ForwardX11Trusted
456.It GatewayPorts
457.It GlobalKnownHostsFile
458.It GSSAPIAuthentication
459.It GSSAPIDelegateCredentials
460.It HashKnownHosts
461.It Host
462.It HostbasedAuthentication
463.It HostKeyAlgorithms
464.It HostKeyAlias
465.It HostName
466.It IdentityFile
467.It IdentitiesOnly
468.It KbdInteractiveDevices
469.It LocalCommand
470.It LocalForward
471.It LogLevel
472.It MACs
473.It NoHostAuthenticationForLocalhost
474.It NumberOfPasswordPrompts
475.It PasswordAuthentication
476.It PermitLocalCommand
477.It PKCS11Provider
478.It Port
479.It PreferredAuthentications
480.It Protocol
481.It ProxyCommand
482.It PubkeyAuthentication
483.It RekeyLimit
484.It RemoteForward
485.It RhostsRSAAuthentication
486.It RSAAuthentication
487.It SendEnv
488.It ServerAliveInterval
489.It ServerAliveCountMax
490.It StrictHostKeyChecking
491.It TCPKeepAlive
492.It Tunnel
493.It TunnelDevice
494.It UsePrivilegedPort
495.It User
496.It UserKnownHostsFile
497.It VerifyHostKeyDNS
498.It VersionAddendum
499.It VisualHostKey
500.It XAuthLocation
501.El
502.It Fl p Ar port
503Port to connect to on the remote host.
504This can be specified on a
505per-host basis in the configuration file.
506.It Fl q
507Quiet mode.
508Causes most warning and diagnostic messages to be suppressed.
509.It Fl R Xo
510.Sm off
511.Oo Ar bind_address : Oc
512.Ar port : host : hostport
513.Sm on
514.Xc
515Specifies that the given port on the remote (server) host is to be
516forwarded to the given host and port on the local side.
517This works by allocating a socket to listen to
518.Ar port
519on the remote side, and whenever a connection is made to this port, the
520connection is forwarded over the secure channel, and a connection is
521made to
522.Ar host
523port
524.Ar hostport
525from the local machine.
526.Pp
527Port forwardings can also be specified in the configuration file.
528Privileged ports can be forwarded only when
529logging in as root on the remote machine.
530IPv6 addresses can be specified by enclosing the address in square braces or
531using an alternative syntax:
532.Sm off
533.Xo
534.Op Ar bind_address No /
535.Ar host No / Ar port No /
536.Ar hostport
537.Xc .
538.Sm on
539.Pp
540By default, the listening socket on the server will be bound to the loopback
541interface only.
542This may be overridden by specifying a
543.Ar bind_address .
544An empty
545.Ar bind_address ,
546or the address
547.Ql * ,
548indicates that the remote socket should listen on all interfaces.
549Specifying a remote
550.Ar bind_address
551will only succeed if the server's
552.Cm GatewayPorts
553option is enabled (see
554.Xr sshd_config 5 ) .
555.Pp
556If the
557.Ar port
558argument is
559.Ql 0 ,
560the listen port will be dynamically allocated on the server and reported
561to the client at run time.
562.It Fl S Ar ctl_path
563Specifies the location of a control socket for connection sharing.
564Refer to the description of
565.Cm ControlPath
566and
567.Cm ControlMaster
568in
569.Xr ssh_config 5
570for details.
571.It Fl s
572May be used to request invocation of a subsystem on the remote system.
573Subsystems are a feature of the SSH2 protocol which facilitate the use
574of SSH as a secure transport for other applications (eg.\&
575.Xr sftp 1 ) .
576The subsystem is specified as the remote command.
577.It Fl T
578Disable pseudo-tty allocation.
579.It Fl t
580Force pseudo-tty allocation.
581This can be used to execute arbitrary
582screen-based programs on a remote machine, which can be very useful,
583e.g. when implementing menu services.
584Multiple
585.Fl t
586options force tty allocation, even if
587.Nm
588has no local tty.
589.It Fl V
590Display the version number and exit.
591.It Fl v
592Verbose mode.
593Causes
594.Nm
595to print debugging messages about its progress.
596This is helpful in
597debugging connection, authentication, and configuration problems.
598Multiple
599.Fl v
600options increase the verbosity.
601The maximum is 3.
602.It Fl W Ar host : Ns Ar port
603Requests that standard input and output on the client be forwarded to
604.Ar host
605on
606.Ar port
607over the secure channel.
608Implies
609.Fl N ,
610.Fl T ,
611.Cm ExitOnForwardFailure
612and
613.Cm ClearAllForwardings
614and works with Protocol version 2 only.
615.It Fl w Xo
616.Ar local_tun Ns Op : Ns Ar remote_tun
617.Xc
618Requests
619tunnel
620device forwarding with the specified
621.Xr tun 4
622devices between the client
623.Pq Ar local_tun
624and the server
625.Pq Ar remote_tun .
626.Pp
627The devices may be specified by numerical ID or the keyword
628.Dq any ,
629which uses the next available tunnel device.
630If
631.Ar remote_tun
632is not specified, it defaults to
633.Dq any .
634See also the
635.Cm Tunnel
636and
637.Cm TunnelDevice
638directives in
639.Xr ssh_config 5 .
640If the
641.Cm Tunnel
642directive is unset, it is set to the default tunnel mode, which is
643.Dq point-to-point .
644.It Fl X
645Enables X11 forwarding.
646This can also be specified on a per-host basis in a configuration file.
647.Pp
648X11 forwarding should be enabled with caution.
649Users with the ability to bypass file permissions on the remote host
650(for the user's X authorization database)
651can access the local X11 display through the forwarded connection.
652An attacker may then be able to perform activities such as keystroke monitoring.
653.Pp
654For this reason, X11 forwarding is subjected to X11 SECURITY extension
655restrictions by default.
656Please refer to the
657.Nm
658.Fl Y
659option and the
660.Cm ForwardX11Trusted
661directive in
662.Xr ssh_config 5
663for more information.
664.It Fl x
665Disables X11 forwarding.
666.It Fl Y
667Enables trusted X11 forwarding.
668Trusted X11 forwardings are not subjected to the X11 SECURITY extension
669controls.
670.It Fl y
671Send log information using the
672.Xr syslog 3
673system module.
674By default this information is sent to stderr.
675.El
676.Pp
677.Nm
678may additionally obtain configuration data from
679a per-user configuration file and a system-wide configuration file.
680The file format and configuration options are described in
681.Xr ssh_config 5 .
682.Pp
683.Nm
684exits with the exit status of the remote command or with 255
685if an error occurred.
686.Sh AUTHENTICATION
687The OpenSSH SSH client supports SSH protocols 1 and 2.
688The default is to use protocol 2 only,
689though this can be changed via the
690.Cm Protocol
691option in
692.Xr ssh_config 5
693or the
694.Fl 1
695and
696.Fl 2
697options (see above).
698Both protocols support similar authentication methods,
699but protocol 2 is the default since
700it provides additional mechanisms for confidentiality
701(the traffic is encrypted using AES, 3DES, Blowfish, CAST128, or Arcfour)
702and integrity (hmac-md5, hmac-sha1, umac-64, hmac-ripemd160).
703Protocol 1 lacks a strong mechanism for ensuring the
704integrity of the connection.
705.Pp
706The methods available for authentication are:
707GSSAPI-based authentication,
708host-based authentication,
709public key authentication,
710challenge-response authentication,
711and password authentication.
712Authentication methods are tried in the order specified above,
713though protocol 2 has a configuration option to change the default order:
714.Cm PreferredAuthentications .
715.Pp
716Host-based authentication works as follows:
717If the machine the user logs in from is listed in
718.Pa /etc/hosts.equiv
719or
720.Pa /etc/shosts.equiv
721on the remote machine, and the user names are
722the same on both sides, or if the files
723.Pa ~/.rhosts
724or
725.Pa ~/.shosts
726exist in the user's home directory on the
727remote machine and contain a line containing the name of the client
728machine and the name of the user on that machine, the user is
729considered for login.
730Additionally, the server
731.Em must
732be able to verify the client's
733host key (see the description of
734.Pa /etc/ssh/ssh_known_hosts
735and
736.Pa ~/.ssh/known_hosts ,
737below)
738for login to be permitted.
739This authentication method closes security holes due to IP
740spoofing, DNS spoofing, and routing spoofing.
741[Note to the administrator:
742.Pa /etc/hosts.equiv ,
743.Pa ~/.rhosts ,
744and the rlogin/rsh protocol in general, are inherently insecure and should be
745disabled if security is desired.]
746.Pp
747Public key authentication works as follows:
748The scheme is based on public-key cryptography,
749using cryptosystems
750where encryption and decryption are done using separate keys,
751and it is unfeasible to derive the decryption key from the encryption key.
752The idea is that each user creates a public/private
753key pair for authentication purposes.
754The server knows the public key, and only the user knows the private key.
755.Nm
756implements public key authentication protocol automatically,
757using either the RSA or DSA algorithms.
758Protocol 1 is restricted to using only RSA keys,
759but protocol 2 may use either.
760The
761.Sx HISTORY
762section of
763.Xr ssl 8
764contains a brief discussion of the two algorithms.
765.Pp
766The file
767.Pa ~/.ssh/authorized_keys
768lists the public keys that are permitted for logging in.
769When the user logs in, the
770.Nm
771program tells the server which key pair it would like to use for
772authentication.
773The client proves that it has access to the private key
774and the server checks that the corresponding public key
775is authorized to accept the account.
776.Pp
777The user creates his/her key pair by running
778.Xr ssh-keygen 1 .
779This stores the private key in
780.Pa ~/.ssh/identity
781(protocol 1),
782.Pa ~/.ssh/id_dsa
783(protocol 2 DSA),
784or
785.Pa ~/.ssh/id_rsa
786(protocol 2 RSA)
787and stores the public key in
788.Pa ~/.ssh/identity.pub
789(protocol 1),
790.Pa ~/.ssh/id_dsa.pub
791(protocol 2 DSA),
792or
793.Pa ~/.ssh/id_rsa.pub
794(protocol 2 RSA)
795in the user's home directory.
796The user should then copy the public key
797to
798.Pa ~/.ssh/authorized_keys
799in his/her home directory on the remote machine.
800The
801.Pa authorized_keys
802file corresponds to the conventional
803.Pa ~/.rhosts
804file, and has one key
805per line, though the lines can be very long.
806After this, the user can log in without giving the password.
807.Pp
808A variation on public key authentication
809is available in the form of certificate authentication:
810instead of a set of public/private keys,
811signed certificates are used.
812This has the advantage that a single trusted certification authority
813can be used in place of many public/private keys.
814See the
815.Sx CERTIFICATES
816section of
817.Xr ssh-keygen 1
818for more information.
819.Pp
820The most convenient way to use public key or certificate authentication
821may be with an authentication agent.
822See
823.Xr ssh-agent 1
824for more information.
825.Pp
826Challenge-response authentication works as follows:
827The server sends an arbitrary
828.Qq challenge
829text, and prompts for a response.
830Protocol 2 allows multiple challenges and responses;
831protocol 1 is restricted to just one challenge/response.
832Examples of challenge-response authentication include
833BSD Authentication (see
834.Xr login.conf 5 )
835and PAM (some non-OpenBSD systems).
836.Pp
837Finally, if other authentication methods fail,
838.Nm
839prompts the user for a password.
840The password is sent to the remote
841host for checking; however, since all communications are encrypted,
842the password cannot be seen by someone listening on the network.
843.Pp
844.Nm
845automatically maintains and checks a database containing
846identification for all hosts it has ever been used with.
847Host keys are stored in
848.Pa ~/.ssh/known_hosts
849in the user's home directory.
850Additionally, the file
851.Pa /etc/ssh/ssh_known_hosts
852is automatically checked for known hosts.
853Any new hosts are automatically added to the user's file.
854If a host's identification ever changes,
855.Nm
856warns about this and disables password authentication to prevent
857server spoofing or man-in-the-middle attacks,
858which could otherwise be used to circumvent the encryption.
859The
860.Cm StrictHostKeyChecking
861option can be used to control logins to machines whose
862host key is not known or has changed.
863.Pp
864When the user's identity has been accepted by the server, the server
865either executes the given command, or logs into the machine and gives
866the user a normal shell on the remote machine.
867All communication with
868the remote command or shell will be automatically encrypted.
869.Pp
870If a pseudo-terminal has been allocated (normal login session), the
871user may use the escape characters noted below.
872.Pp
873If no pseudo-tty has been allocated,
874the session is transparent and can be used to reliably transfer binary data.
875On most systems, setting the escape character to
876.Dq none
877will also make the session transparent even if a tty is used.
878.Pp
879The session terminates when the command or shell on the remote
880machine exits and all X11 and TCP connections have been closed.
881.Sh ESCAPE CHARACTERS
882When a pseudo-terminal has been requested,
883.Nm
884supports a number of functions through the use of an escape character.
885.Pp
886A single tilde character can be sent as
887.Ic ~~
888or by following the tilde by a character other than those described below.
889The escape character must always follow a newline to be interpreted as
890special.
891The escape character can be changed in configuration files using the
892.Cm EscapeChar
893configuration directive or on the command line by the
894.Fl e
895option.
896.Pp
897The supported escapes (assuming the default
898.Ql ~ )
899are:
900.Bl -tag -width Ds
901.It Cm ~.
902Disconnect.
903.It Cm ~^Z
904Background
905.Nm .
906.It Cm ~#
907List forwarded connections.
908.It Cm ~&
909Background
910.Nm
911at logout when waiting for forwarded connection / X11 sessions to terminate.
912.It Cm ~?
913Display a list of escape characters.
914.It Cm ~B
915Send a BREAK to the remote system
916(only useful for SSH protocol version 2 and if the peer supports it).
917.It Cm ~C
918Open command line.
919Currently this allows the addition of port forwardings using the
920.Fl L ,
921.Fl R
922and
923.Fl D
924options (see above).
925It also allows the cancellation of existing remote port-forwardings
926using
927.Sm off
928.Fl KR Oo Ar bind_address : Oc Ar port .
929.Sm on
930.Ic !\& Ns Ar command
931allows the user to execute a local command if the
932.Ic PermitLocalCommand
933option is enabled in
934.Xr ssh_config 5 .
935Basic help is available, using the
936.Fl h
937option.
938.It Cm ~R
939Request rekeying of the connection
940(only useful for SSH protocol version 2 and if the peer supports it).
941.El
942.Sh TCP FORWARDING
943Forwarding of arbitrary TCP connections over the secure channel can
944be specified either on the command line or in a configuration file.
945One possible application of TCP forwarding is a secure connection to a
946mail server; another is going through firewalls.
947.Pp
948In the example below, we look at encrypting communication between
949an IRC client and server, even though the IRC server does not directly
950support encrypted communications.
951This works as follows:
952the user connects to the remote host using
953.Nm ,
954specifying a port to be used to forward connections
955to the remote server.
956After that it is possible to start the service which is to be encrypted
957on the client machine,
958connecting to the same local port,
959and
960.Nm
961will encrypt and forward the connection.
962.Pp
963The following example tunnels an IRC session from client machine
964.Dq 127.0.0.1
965(localhost)
966to remote server
967.Dq server.example.com :
968.Bd -literal -offset 4n
969$ ssh -f -L 1234:localhost:6667 server.example.com sleep 10
970$ irc -c '#users' -p 1234 pinky 127.0.0.1
971.Ed
972.Pp
973This tunnels a connection to IRC server
974.Dq server.example.com ,
975joining channel
976.Dq #users ,
977nickname
978.Dq pinky ,
979using port 1234.
980It doesn't matter which port is used,
981as long as it's greater than 1023
982(remember, only root can open sockets on privileged ports)
983and doesn't conflict with any ports already in use.
984The connection is forwarded to port 6667 on the remote server,
985since that's the standard port for IRC services.
986.Pp
987The
988.Fl f
989option backgrounds
990.Nm
991and the remote command
992.Dq sleep 10
993is specified to allow an amount of time
994(10 seconds, in the example)
995to start the service which is to be tunnelled.
996If no connections are made within the time specified,
997.Nm
998will exit.
999.Sh X11 FORWARDING
1000If the
1001.Cm ForwardX11
1002variable is set to
1003.Dq yes
1004(or see the description of the
1005.Fl X ,
1006.Fl x ,
1007and
1008.Fl Y
1009options above)
1010and the user is using X11 (the
1011.Ev DISPLAY
1012environment variable is set), the connection to the X11 display is
1013automatically forwarded to the remote side in such a way that any X11
1014programs started from the shell (or command) will go through the
1015encrypted channel, and the connection to the real X server will be made
1016from the local machine.
1017The user should not manually set
1018.Ev DISPLAY .
1019Forwarding of X11 connections can be
1020configured on the command line or in configuration files.
1021.Pp
1022The
1023.Ev DISPLAY
1024value set by
1025.Nm
1026will point to the server machine, but with a display number greater than zero.
1027This is normal, and happens because
1028.Nm
1029creates a
1030.Dq proxy
1031X server on the server machine for forwarding the
1032connections over the encrypted channel.
1033.Pp
1034.Nm
1035will also automatically set up Xauthority data on the server machine.
1036For this purpose, it will generate a random authorization cookie,
1037store it in Xauthority on the server, and verify that any forwarded
1038connections carry this cookie and replace it by the real cookie when
1039the connection is opened.
1040The real authentication cookie is never
1041sent to the server machine (and no cookies are sent in the plain).
1042.Pp
1043If the
1044.Cm ForwardAgent
1045variable is set to
1046.Dq yes
1047(or see the description of the
1048.Fl A
1049and
1050.Fl a
1051options above) and
1052the user is using an authentication agent, the connection to the agent
1053is automatically forwarded to the remote side.
1054.Sh VERIFYING HOST KEYS
1055When connecting to a server for the first time,
1056a fingerprint of the server's public key is presented to the user
1057(unless the option
1058.Cm StrictHostKeyChecking
1059has been disabled).
1060Fingerprints can be determined using
1061.Xr ssh-keygen 1 :
1062.Pp
1063.Dl $ ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key
1064.Pp
1065If the fingerprint is already known, it can be matched
1066and the key can be accepted or rejected.
1067Because of the difficulty of comparing host keys
1068just by looking at hex strings,
1069there is also support to compare host keys visually,
1070using
1071.Em random art .
1072By setting the
1073.Cm VisualHostKey
1074option to
1075.Dq yes ,
1076a small ASCII graphic gets displayed on every login to a server, no matter
1077if the session itself is interactive or not.
1078By learning the pattern a known server produces, a user can easily
1079find out that the host key has changed when a completely different pattern
1080is displayed.
1081Because these patterns are not unambiguous however, a pattern that looks
1082similar to the pattern remembered only gives a good probability that the
1083host key is the same, not guaranteed proof.
1084.Pp
1085To get a listing of the fingerprints along with their random art for
1086all known hosts, the following command line can be used:
1087.Pp
1088.Dl $ ssh-keygen -lv -f ~/.ssh/known_hosts
1089.Pp
1090If the fingerprint is unknown,
1091an alternative method of verification is available:
1092SSH fingerprints verified by DNS.
1093An additional resource record (RR),
1094SSHFP,
1095is added to a zonefile
1096and the connecting client is able to match the fingerprint
1097with that of the key presented.
1098.Pp
1099In this example, we are connecting a client to a server,
1100.Dq host.example.com .
1101The SSHFP resource records should first be added to the zonefile for
1102host.example.com:
1103.Bd -literal -offset indent
1104$ ssh-keygen -r host.example.com.
1105.Ed
1106.Pp
1107The output lines will have to be added to the zonefile.
1108To check that the zone is answering fingerprint queries:
1109.Pp
1110.Dl $ dig -t SSHFP host.example.com
1111.Pp
1112Finally the client connects:
1113.Bd -literal -offset indent
1114$ ssh -o "VerifyHostKeyDNS ask" host.example.com
1115[...]
1116Matching host key fingerprint found in DNS.
1117Are you sure you want to continue connecting (yes/no)?
1118.Ed
1119.Pp
1120See the
1121.Cm VerifyHostKeyDNS
1122option in
1123.Xr ssh_config 5
1124for more information.
1125.Sh SSH-BASED VIRTUAL PRIVATE NETWORKS
1126.Nm
1127contains support for Virtual Private Network (VPN) tunnelling
1128using the
1129.Xr tun 4
1130network pseudo-device,
1131allowing two networks to be joined securely.
1132The
1133.Xr sshd_config 5
1134configuration option
1135.Cm PermitTunnel
1136controls whether the server supports this,
1137and at what level (layer 2 or 3 traffic).
1138.Pp
1139The following example would connect client network 10.0.50.0/24
1140with remote network 10.0.99.0/24 using a point-to-point connection
1141from 10.1.1.1 to 10.1.1.2,
1142provided that the SSH server running on the gateway to the remote network,
1143at 192.168.1.15, allows it.
1144.Pp
1145On the client:
1146.Bd -literal -offset indent
1147# ssh -f -w 0:1 192.168.1.15 true
1148# ifconfig tun0 10.1.1.1 10.1.1.2 netmask 255.255.255.252
1149# route add 10.0.99.0/24 10.1.1.2
1150.Ed
1151.Pp
1152On the server:
1153.Bd -literal -offset indent
1154# ifconfig tun1 10.1.1.2 10.1.1.1 netmask 255.255.255.252
1155# route add 10.0.50.0/24 10.1.1.1
1156.Ed
1157.Pp
1158Client access may be more finely tuned via the
1159.Pa /root/.ssh/authorized_keys
1160file (see below) and the
1161.Cm PermitRootLogin
1162server option.
1163The following entry would permit connections on
1164.Xr tun 4
1165device 1 from user
1166.Dq jane
1167and on tun device 2 from user
1168.Dq john ,
1169if
1170.Cm PermitRootLogin
1171is set to
1172.Dq forced-commands-only :
1173.Bd -literal -offset 2n
1174tunnel="1",command="sh /etc/netstart tun1" ssh-rsa ... jane
1175tunnel="2",command="sh /etc/netstart tun2" ssh-rsa ... john
1176.Ed
1177.Pp
1178Since an SSH-based setup entails a fair amount of overhead,
1179it may be more suited to temporary setups,
1180such as for wireless VPNs.
1181More permanent VPNs are better provided by tools such as
1182.Xr ipsecctl 8
1183and
1184.Xr isakmpd 8 .
1185.Sh ENVIRONMENT
1186.Nm
1187will normally set the following environment variables:
1188.Bl -tag -width "SSH_ORIGINAL_COMMAND"
1189.It Ev DISPLAY
1190The
1191.Ev DISPLAY
1192variable indicates the location of the X11 server.
1193It is automatically set by
1194.Nm
1195to point to a value of the form
1196.Dq hostname:n ,
1197where
1198.Dq hostname
1199indicates the host where the shell runs, and
1200.Sq n
1201is an integer \*(Ge 1.
1202.Nm
1203uses this special value to forward X11 connections over the secure
1204channel.
1205The user should normally not set
1206.Ev DISPLAY
1207explicitly, as that
1208will render the X11 connection insecure (and will require the user to
1209manually copy any required authorization cookies).
1210.It Ev HOME
1211Set to the path of the user's home directory.
1212.It Ev LOGNAME
1213Synonym for
1214.Ev USER ;
1215set for compatibility with systems that use this variable.
1216.It Ev MAIL
1217Set to the path of the user's mailbox.
1218.It Ev PATH
1219Set to the default
1220.Ev PATH ,
1221as specified when compiling
1222.Nm .
1223.It Ev SSH_ASKPASS
1224If
1225.Nm
1226needs a passphrase, it will read the passphrase from the current
1227terminal if it was run from a terminal.
1228If
1229.Nm
1230does not have a terminal associated with it but
1231.Ev DISPLAY
1232and
1233.Ev SSH_ASKPASS
1234are set, it will execute the program specified by
1235.Ev SSH_ASKPASS
1236and open an X11 window to read the passphrase.
1237This is particularly useful when calling
1238.Nm
1239from a
1240.Pa .xsession
1241or related script.
1242(Note that on some machines it
1243may be necessary to redirect the input from
1244.Pa /dev/null
1245to make this work.)
1246.It Ev SSH_AUTH_SOCK
1247Identifies the path of a
1248.Ux Ns -domain
1249socket used to communicate with the agent.
1250.It Ev SSH_CONNECTION
1251Identifies the client and server ends of the connection.
1252The variable contains
1253four space-separated values: client IP address, client port number,
1254server IP address, and server port number.
1255.It Ev SSH_ORIGINAL_COMMAND
1256This variable contains the original command line if a forced command
1257is executed.
1258It can be used to extract the original arguments.
1259.It Ev SSH_TTY
1260This is set to the name of the tty (path to the device) associated
1261with the current shell or command.
1262If the current session has no tty,
1263this variable is not set.
1264.It Ev TZ
1265This variable is set to indicate the present time zone if it
1266was set when the daemon was started (i.e. the daemon passes the value
1267on to new connections).
1268.It Ev USER
1269Set to the name of the user logging in.
1270.El
1271.Pp
1272Additionally,
1273.Nm
1274reads
1275.Pa ~/.ssh/environment ,
1276and adds lines of the format
1277.Dq VARNAME=value
1278to the environment if the file exists and users are allowed to
1279change their environment.
1280For more information, see the
1281.Cm PermitUserEnvironment
1282option in
1283.Xr sshd_config 5 .
1284.Sh FILES
1285.Bl -tag -width Ds -compact
1286.It ~/.rhosts
1287This file is used for host-based authentication (see above).
1288On some machines this file may need to be
1289world-readable if the user's home directory is on an NFS partition,
1290because
1291.Xr sshd 8
1292reads it as root.
1293Additionally, this file must be owned by the user,
1294and must not have write permissions for anyone else.
1295The recommended
1296permission for most machines is read/write for the user, and not
1297accessible by others.
1298.Pp
1299.It ~/.shosts
1300This file is used in exactly the same way as
1301.Pa .rhosts ,
1302but allows host-based authentication without permitting login with
1303rlogin/rsh.
1304.Pp
1305.It ~/.ssh/
1306This directory is the default location for all user-specific configuration
1307and authentication information.
1308There is no general requirement to keep the entire contents of this directory
1309secret, but the recommended permissions are read/write/execute for the user,
1310and not accessible by others.
1311.Pp
1312.It ~/.ssh/authorized_keys
1313Lists the public keys (RSA/DSA) that can be used for logging in as this user.
1314The format of this file is described in the
1315.Xr sshd 8
1316manual page.
1317This file is not highly sensitive, but the recommended
1318permissions are read/write for the user, and not accessible by others.
1319.Pp
1320.It ~/.ssh/config
1321This is the per-user configuration file.
1322The file format and configuration options are described in
1323.Xr ssh_config 5 .
1324Because of the potential for abuse, this file must have strict permissions:
1325read/write for the user, and not accessible by others.
1326.Pp
1327.It ~/.ssh/environment
1328Contains additional definitions for environment variables; see
1329.Sx ENVIRONMENT ,
1330above.
1331.Pp
1332.It ~/.ssh/identity
1333.It ~/.ssh/id_dsa
1334.It ~/.ssh/id_rsa
1335Contains the private key for authentication.
1336These files
1337contain sensitive data and should be readable by the user but not
1338accessible by others (read/write/execute).
1339.Nm
1340will simply ignore a private key file if it is accessible by others.
1341It is possible to specify a passphrase when
1342generating the key which will be used to encrypt the
1343sensitive part of this file using 3DES.
1344.Pp
1345.It ~/.ssh/identity.pub
1346.It ~/.ssh/id_dsa.pub
1347.It ~/.ssh/id_rsa.pub
1348Contains the public key for authentication.
1349These files are not
1350sensitive and can (but need not) be readable by anyone.
1351.Pp
1352.It ~/.ssh/known_hosts
1353Contains a list of host keys for all hosts the user has logged into
1354that are not already in the systemwide list of known host keys.
1355See
1356.Xr sshd 8
1357for further details of the format of this file.
1358.Pp
1359.It ~/.ssh/rc
1360Commands in this file are executed by
1361.Nm
1362when the user logs in, just before the user's shell (or command) is
1363started.
1364See the
1365.Xr sshd 8
1366manual page for more information.
1367.Pp
1368.It /etc/hosts.equiv
1369This file is for host-based authentication (see above).
1370It should only be writable by root.
1371.Pp
1372.It /etc/shosts.equiv
1373This file is used in exactly the same way as
1374.Pa hosts.equiv ,
1375but allows host-based authentication without permitting login with
1376rlogin/rsh.
1377.Pp
1378.It Pa /etc/ssh/ssh_config
1379Systemwide configuration file.
1380The file format and configuration options are described in
1381.Xr ssh_config 5 .
1382.Pp
1383.It /etc/ssh/ssh_host_key
1384.It /etc/ssh/ssh_host_dsa_key
1385.It /etc/ssh/ssh_host_rsa_key
1386These three files contain the private parts of the host keys
1387and are used for host-based authentication.
1388If protocol version 1 is used,
1389.Nm
1390must be setuid root, since the host key is readable only by root.
1391For protocol version 2,
1392.Nm
1393uses
1394.Xr ssh-keysign 8
1395to access the host keys,
1396eliminating the requirement that
1397.Nm
1398be setuid root when host-based authentication is used.
1399By default
1400.Nm
1401is not setuid root.
1402.Pp
1403.It /etc/ssh/ssh_known_hosts
1404Systemwide list of known host keys.
1405This file should be prepared by the
1406system administrator to contain the public host keys of all machines in the
1407organization.
1408It should be world-readable.
1409See
1410.Xr sshd 8
1411for further details of the format of this file.
1412.Pp
1413.It /etc/ssh/sshrc
1414Commands in this file are executed by
1415.Nm
1416when the user logs in, just before the user's shell (or command) is started.
1417See the
1418.Xr sshd 8
1419manual page for more information.
1420.El
1421.Sh SEE ALSO
1422.Xr scp 1 ,
1423.Xr sftp 1 ,
1424.Xr ssh-add 1 ,
1425.Xr ssh-agent 1 ,
1426.Xr ssh-keygen 1 ,
1427.Xr ssh-keyscan 1 ,
1428.Xr tun 4 ,
1429.Xr hosts.equiv 5 ,
1430.Xr ssh_config 5 ,
1431.Xr ssh-keysign 8 ,
1432.Xr sshd 8
1433.Rs
1434.%R RFC 4250
1435.%T "The Secure Shell (SSH) Protocol Assigned Numbers"
1436.%D 2006
1437.Re
1438.Rs
1439.%R RFC 4251
1440.%T "The Secure Shell (SSH) Protocol Architecture"
1441.%D 2006
1442.Re
1443.Rs
1444.%R RFC 4252
1445.%T "The Secure Shell (SSH) Authentication Protocol"
1446.%D 2006
1447.Re
1448.Rs
1449.%R RFC 4253
1450.%T "The Secure Shell (SSH) Transport Layer Protocol"
1451.%D 2006
1452.Re
1453.Rs
1454.%R RFC 4254
1455.%T "The Secure Shell (SSH) Connection Protocol"
1456.%D 2006
1457.Re
1458.Rs
1459.%R RFC 4255
1460.%T "Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints"
1461.%D 2006
1462.Re
1463.Rs
1464.%R RFC 4256
1465.%T "Generic Message Exchange Authentication for the Secure Shell Protocol (SSH)"
1466.%D 2006
1467.Re
1468.Rs
1469.%R RFC 4335
1470.%T "The Secure Shell (SSH) Session Channel Break Extension"
1471.%D 2006
1472.Re
1473.Rs
1474.%R RFC 4344
1475.%T "The Secure Shell (SSH) Transport Layer Encryption Modes"
1476.%D 2006
1477.Re
1478.Rs
1479.%R RFC 4345
1480.%T "Improved Arcfour Modes for the Secure Shell (SSH) Transport Layer Protocol"
1481.%D 2006
1482.Re
1483.Rs
1484.%R RFC 4419
1485.%T "Diffie-Hellman Group Exchange for the Secure Shell (SSH) Transport Layer Protocol"
1486.%D 2006
1487.Re
1488.Rs
1489.%R RFC 4716
1490.%T "The Secure Shell (SSH) Public Key File Format"
1491.%D 2006
1492.Re
1493.Rs
1494.%T "Hash Visualization: a New Technique to improve Real-World Security"
1495.%A A. Perrig
1496.%A D. Song
1497.%D 1999
1498.%O "International Workshop on Cryptographic Techniques and E-Commerce (CrypTEC '99)"
1499.Re
1500.Sh AUTHORS
1501OpenSSH is a derivative of the original and free
1502ssh 1.2.12 release by Tatu Ylonen.
1503Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos,
1504Theo de Raadt and Dug Song
1505removed many bugs, re-added newer features and
1506created OpenSSH.
1507Markus Friedl contributed the support for SSH
1508protocol versions 1.5 and 2.0.
1509