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