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