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.320 2011/08/02 01:22:11 djm Exp $ 37.\" $FreeBSD$ 38.Dd August 2, 2011 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), 397.Dq exit 398(request the master to exit), and 399.Dq stop 400(request the master to stop accepting further multiplexing requests). 401.It Fl o Ar option 402Can be used to give options in the format used in the configuration file. 403This is useful for specifying options for which there is no separate 404command-line flag. 405For full details of the options listed below, and their possible values, see 406.Xr ssh_config 5 . 407.Pp 408.Bl -tag -width Ds -offset indent -compact 409.It AddressFamily 410.It BatchMode 411.It BindAddress 412.It ChallengeResponseAuthentication 413.It CheckHostIP 414.It Cipher 415.It Ciphers 416.It ClearAllForwardings 417.It Compression 418.It CompressionLevel 419.It ConnectionAttempts 420.It ConnectTimeout 421.It ControlMaster 422.It ControlPath 423.It DynamicForward 424.It EscapeChar 425.It ExitOnForwardFailure 426.It ForwardAgent 427.It ForwardX11 428.It ForwardX11Trusted 429.It GatewayPorts 430.It GlobalKnownHostsFile 431.It GSSAPIAuthentication 432.It GSSAPIDelegateCredentials 433.It HashKnownHosts 434.It Host 435.It HostbasedAuthentication 436.It HostKeyAlgorithms 437.It HostKeyAlias 438.It HostName 439.It IdentityFile 440.It IdentitiesOnly 441.It IPQoS 442.It KbdInteractiveDevices 443.It KexAlgorithms 444.It LocalCommand 445.It LocalForward 446.It LogLevel 447.It MACs 448.It NoHostAuthenticationForLocalhost 449.It NumberOfPasswordPrompts 450.It PasswordAuthentication 451.It PermitLocalCommand 452.It PKCS11Provider 453.It Port 454.It PreferredAuthentications 455.It Protocol 456.It ProxyCommand 457.It PubkeyAuthentication 458.It RekeyLimit 459.It RemoteForward 460.It RequestTTY 461.It RhostsRSAAuthentication 462.It RSAAuthentication 463.It SendEnv 464.It ServerAliveInterval 465.It ServerAliveCountMax 466.It StrictHostKeyChecking 467.It TCPKeepAlive 468.It Tunnel 469.It TunnelDevice 470.It UsePrivilegedPort 471.It User 472.It UserKnownHostsFile 473.It VerifyHostKeyDNS 474.It VersionAddendum 475.It VisualHostKey 476.It XAuthLocation 477.El 478.It Fl p Ar port 479Port to connect to on the remote host. 480This can be specified on a 481per-host basis in the configuration file. 482.It Fl q 483Quiet mode. 484Causes most warning and diagnostic messages to be suppressed. 485.It Fl R Xo 486.Sm off 487.Oo Ar bind_address : Oc 488.Ar port : host : hostport 489.Sm on 490.Xc 491Specifies that the given port on the remote (server) host is to be 492forwarded to the given host and port on the local side. 493This works by allocating a socket to listen to 494.Ar port 495on the remote side, and whenever a connection is made to this port, the 496connection is forwarded over the secure channel, and a connection is 497made to 498.Ar host 499port 500.Ar hostport 501from the local machine. 502.Pp 503Port forwardings can also be specified in the configuration file. 504Privileged ports can be forwarded only when 505logging in as root on the remote machine. 506IPv6 addresses can be specified by enclosing the address in square braces. 507.Pp 508By default, the listening socket on the server will be bound to the loopback 509interface only. 510This may be overridden by specifying a 511.Ar bind_address . 512An empty 513.Ar bind_address , 514or the address 515.Ql * , 516indicates that the remote socket should listen on all interfaces. 517Specifying a remote 518.Ar bind_address 519will only succeed if the server's 520.Cm GatewayPorts 521option is enabled (see 522.Xr sshd_config 5 ) . 523.Pp 524If the 525.Ar port 526argument is 527.Ql 0 , 528the listen port will be dynamically allocated on the server and reported 529to the client at run time. 530When used together with 531.Ic -O forward 532the allocated port will be printed to the standard output. 533.It Fl S Ar ctl_path 534Specifies the location of a control socket for connection sharing, 535or the string 536.Dq none 537to disable connection sharing. 538Refer to the description of 539.Cm ControlPath 540and 541.Cm ControlMaster 542in 543.Xr ssh_config 5 544for details. 545.It Fl s 546May be used to request invocation of a subsystem on the remote system. 547Subsystems are a feature of the SSH2 protocol which facilitate the use 548of SSH as a secure transport for other applications (eg.\& 549.Xr sftp 1 ) . 550The subsystem is specified as the remote command. 551.It Fl T 552Disable pseudo-tty allocation. 553.It Fl t 554Force pseudo-tty allocation. 555This can be used to execute arbitrary 556screen-based programs on a remote machine, which can be very useful, 557e.g. when implementing menu services. 558Multiple 559.Fl t 560options force tty allocation, even if 561.Nm 562has no local tty. 563.It Fl V 564Display the version number and exit. 565.It Fl v 566Verbose mode. 567Causes 568.Nm 569to print debugging messages about its progress. 570This is helpful in 571debugging connection, authentication, and configuration problems. 572Multiple 573.Fl v 574options increase the verbosity. 575The maximum is 3. 576.It Fl W Ar host : Ns Ar port 577Requests that standard input and output on the client be forwarded to 578.Ar host 579on 580.Ar port 581over the secure channel. 582Implies 583.Fl N , 584.Fl T , 585.Cm ExitOnForwardFailure 586and 587.Cm ClearAllForwardings 588and works with Protocol version 2 only. 589.It Fl w Xo 590.Ar local_tun Ns Op : Ns Ar remote_tun 591.Xc 592Requests 593tunnel 594device forwarding with the specified 595.Xr tun 4 596devices between the client 597.Pq Ar local_tun 598and the server 599.Pq Ar remote_tun . 600.Pp 601The devices may be specified by numerical ID or the keyword 602.Dq any , 603which uses the next available tunnel device. 604If 605.Ar remote_tun 606is not specified, it defaults to 607.Dq any . 608See also the 609.Cm Tunnel 610and 611.Cm TunnelDevice 612directives in 613.Xr ssh_config 5 . 614If the 615.Cm Tunnel 616directive is unset, it is set to the default tunnel mode, which is 617.Dq point-to-point . 618.It Fl X 619Enables X11 forwarding. 620This can also be specified on a per-host basis in a configuration file. 621.Pp 622X11 forwarding should be enabled with caution. 623Users with the ability to bypass file permissions on the remote host 624(for the user's X authorization database) 625can access the local X11 display through the forwarded connection. 626An attacker may then be able to perform activities such as keystroke monitoring. 627.Pp 628For this reason, X11 forwarding is subjected to X11 SECURITY extension 629restrictions by default. 630Please refer to the 631.Nm 632.Fl Y 633option and the 634.Cm ForwardX11Trusted 635directive in 636.Xr ssh_config 5 637for more information. 638.It Fl x 639Disables X11 forwarding. 640.It Fl Y 641Enables trusted X11 forwarding. 642Trusted X11 forwardings are not subjected to the X11 SECURITY extension 643controls. 644.It Fl y 645Send log information using the 646.Xr syslog 3 647system module. 648By default this information is sent to stderr. 649.El 650.Pp 651.Nm 652may additionally obtain configuration data from 653a per-user configuration file and a system-wide configuration file. 654The file format and configuration options are described in 655.Xr ssh_config 5 . 656.Sh AUTHENTICATION 657The OpenSSH SSH client supports SSH protocols 1 and 2. 658The default is to use protocol 2 only, 659though this can be changed via the 660.Cm Protocol 661option in 662.Xr ssh_config 5 663or the 664.Fl 1 665and 666.Fl 2 667options (see above). 668Both protocols support similar authentication methods, 669but protocol 2 is the default since 670it provides additional mechanisms for confidentiality 671(the traffic is encrypted using AES, 3DES, Blowfish, CAST128, or Arcfour) 672and integrity (hmac-md5, hmac-sha1, 673hmac-sha2-256, hmac-sha2-512, 674umac-64, hmac-ripemd160). 675Protocol 1 lacks a strong mechanism for ensuring the 676integrity of the connection. 677.Pp 678The methods available for authentication are: 679GSSAPI-based authentication, 680host-based authentication, 681public key authentication, 682challenge-response authentication, 683and password authentication. 684Authentication methods are tried in the order specified above, 685though protocol 2 has a configuration option to change the default order: 686.Cm PreferredAuthentications . 687.Pp 688Host-based authentication works as follows: 689If the machine the user logs in from is listed in 690.Pa /etc/hosts.equiv 691or 692.Pa /etc/shosts.equiv 693on the remote machine, and the user names are 694the same on both sides, or if the files 695.Pa ~/.rhosts 696or 697.Pa ~/.shosts 698exist in the user's home directory on the 699remote machine and contain a line containing the name of the client 700machine and the name of the user on that machine, the user is 701considered for login. 702Additionally, the server 703.Em must 704be able to verify the client's 705host key (see the description of 706.Pa /etc/ssh/ssh_known_hosts 707and 708.Pa ~/.ssh/known_hosts , 709below) 710for login to be permitted. 711This authentication method closes security holes due to IP 712spoofing, DNS spoofing, and routing spoofing. 713[Note to the administrator: 714.Pa /etc/hosts.equiv , 715.Pa ~/.rhosts , 716and the rlogin/rsh protocol in general, are inherently insecure and should be 717disabled if security is desired.] 718.Pp 719Public key authentication works as follows: 720The scheme is based on public-key cryptography, 721using cryptosystems 722where encryption and decryption are done using separate keys, 723and it is unfeasible to derive the decryption key from the encryption key. 724The idea is that each user creates a public/private 725key pair for authentication purposes. 726The server knows the public key, and only the user knows the private key. 727.Nm 728implements public key authentication protocol automatically, 729using one of the DSA, ECDSA or RSA algorithms. 730Protocol 1 is restricted to using only RSA keys, 731but protocol 2 may use any. 732The 733.Sx HISTORY 734section of 735.Xr ssl 8 736contains a brief discussion of the DSA and RSA algorithms. 737.Pp 738The file 739.Pa ~/.ssh/authorized_keys 740lists the public keys that are permitted for logging in. 741When the user logs in, the 742.Nm 743program tells the server which key pair it would like to use for 744authentication. 745The client proves that it has access to the private key 746and the server checks that the corresponding public key 747is authorized to accept the account. 748.Pp 749The user creates his/her key pair by running 750.Xr ssh-keygen 1 . 751This stores the private key in 752.Pa ~/.ssh/identity 753(protocol 1), 754.Pa ~/.ssh/id_dsa 755(protocol 2 DSA), 756.Pa ~/.ssh/id_ecdsa 757(protocol 2 ECDSA), 758or 759.Pa ~/.ssh/id_rsa 760(protocol 2 RSA) 761and stores the public key in 762.Pa ~/.ssh/identity.pub 763(protocol 1), 764.Pa ~/.ssh/id_dsa.pub 765(protocol 2 DSA), 766.Pa ~/.ssh/id_ecdsa.pub 767(protocol 2 ECDSA), 768or 769.Pa ~/.ssh/id_rsa.pub 770(protocol 2 RSA) 771in the user's home directory. 772The user should then copy the public key 773to 774.Pa ~/.ssh/authorized_keys 775in his/her home directory on the remote machine. 776The 777.Pa authorized_keys 778file corresponds to the conventional 779.Pa ~/.rhosts 780file, and has one key 781per line, though the lines can be very long. 782After this, the user can log in without giving the password. 783.Pp 784A variation on public key authentication 785is available in the form of certificate authentication: 786instead of a set of public/private keys, 787signed certificates are used. 788This has the advantage that a single trusted certification authority 789can be used in place of many public/private keys. 790See the 791.Sx CERTIFICATES 792section of 793.Xr ssh-keygen 1 794for more information. 795.Pp 796The most convenient way to use public key or certificate authentication 797may be with an authentication agent. 798See 799.Xr ssh-agent 1 800for more information. 801.Pp 802Challenge-response authentication works as follows: 803The server sends an arbitrary 804.Qq challenge 805text, and prompts for a response. 806Protocol 2 allows multiple challenges and responses; 807protocol 1 is restricted to just one challenge/response. 808Examples of challenge-response authentication include 809BSD Authentication (see 810.Xr login.conf 5 ) 811and PAM (some non-OpenBSD systems). 812.Pp 813Finally, if other authentication methods fail, 814.Nm 815prompts the user for a password. 816The password is sent to the remote 817host for checking; however, since all communications are encrypted, 818the password cannot be seen by someone listening on the network. 819.Pp 820.Nm 821automatically maintains and checks a database containing 822identification for all hosts it has ever been used with. 823Host keys are stored in 824.Pa ~/.ssh/known_hosts 825in the user's home directory. 826Additionally, the file 827.Pa /etc/ssh/ssh_known_hosts 828is automatically checked for known hosts. 829Any new hosts are automatically added to the user's file. 830If a host's identification ever changes, 831.Nm 832warns about this and disables password authentication to prevent 833server spoofing or man-in-the-middle attacks, 834which could otherwise be used to circumvent the encryption. 835The 836.Cm StrictHostKeyChecking 837option can be used to control logins to machines whose 838host key is not known or has changed. 839.Pp 840When the user's identity has been accepted by the server, the server 841either executes the given command, or logs into the machine and gives 842the user a normal shell on the remote machine. 843All communication with 844the remote command or shell will be automatically encrypted. 845.Pp 846If a pseudo-terminal has been allocated (normal login session), the 847user may use the escape characters noted below. 848.Pp 849If no pseudo-tty has been allocated, 850the session is transparent and can be used to reliably transfer binary data. 851On most systems, setting the escape character to 852.Dq none 853will also make the session transparent even if a tty is used. 854.Pp 855The session terminates when the command or shell on the remote 856machine exits and all X11 and TCP connections have been closed. 857.Sh ESCAPE CHARACTERS 858When a pseudo-terminal has been requested, 859.Nm 860supports a number of functions through the use of an escape character. 861.Pp 862A single tilde character can be sent as 863.Ic ~~ 864or by following the tilde by a character other than those described below. 865The escape character must always follow a newline to be interpreted as 866special. 867The escape character can be changed in configuration files using the 868.Cm EscapeChar 869configuration directive or on the command line by the 870.Fl e 871option. 872.Pp 873The supported escapes (assuming the default 874.Ql ~ ) 875are: 876.Bl -tag -width Ds 877.It Cm ~. 878Disconnect. 879.It Cm ~^Z 880Background 881.Nm . 882.It Cm ~# 883List forwarded connections. 884.It Cm ~& 885Background 886.Nm 887at logout when waiting for forwarded connection / X11 sessions to terminate. 888.It Cm ~? 889Display a list of escape characters. 890.It Cm ~B 891Send a BREAK to the remote system 892(only useful for SSH protocol version 2 and if the peer supports it). 893.It Cm ~C 894Open command line. 895Currently this allows the addition of port forwardings using the 896.Fl L , 897.Fl R 898and 899.Fl D 900options (see above). 901It also allows the cancellation of existing remote port-forwardings 902using 903.Sm off 904.Fl KR Oo Ar bind_address : Oc Ar port . 905.Sm on 906.Ic !\& Ns Ar command 907allows the user to execute a local command if the 908.Ic PermitLocalCommand 909option is enabled in 910.Xr ssh_config 5 . 911Basic help is available, using the 912.Fl h 913option. 914.It Cm ~R 915Request rekeying of the connection 916(only useful for SSH protocol version 2 and if the peer supports it). 917.El 918.Sh TCP FORWARDING 919Forwarding of arbitrary TCP connections over the secure channel can 920be specified either on the command line or in a configuration file. 921One possible application of TCP forwarding is a secure connection to a 922mail server; another is going through firewalls. 923.Pp 924In the example below, we look at encrypting communication between 925an IRC client and server, even though the IRC server does not directly 926support encrypted communications. 927This works as follows: 928the user connects to the remote host using 929.Nm , 930specifying a port to be used to forward connections 931to the remote server. 932After that it is possible to start the service which is to be encrypted 933on the client machine, 934connecting to the same local port, 935and 936.Nm 937will encrypt and forward the connection. 938.Pp 939The following example tunnels an IRC session from client machine 940.Dq 127.0.0.1 941(localhost) 942to remote server 943.Dq server.example.com : 944.Bd -literal -offset 4n 945$ ssh -f -L 1234:localhost:6667 server.example.com sleep 10 946$ irc -c '#users' -p 1234 pinky 127.0.0.1 947.Ed 948.Pp 949This tunnels a connection to IRC server 950.Dq server.example.com , 951joining channel 952.Dq #users , 953nickname 954.Dq pinky , 955using port 1234. 956It doesn't matter which port is used, 957as long as it's greater than 1023 958(remember, only root can open sockets on privileged ports) 959and doesn't conflict with any ports already in use. 960The connection is forwarded to port 6667 on the remote server, 961since that's the standard port for IRC services. 962.Pp 963The 964.Fl f 965option backgrounds 966.Nm 967and the remote command 968.Dq sleep 10 969is specified to allow an amount of time 970(10 seconds, in the example) 971to start the service which is to be tunnelled. 972If no connections are made within the time specified, 973.Nm 974will exit. 975.Sh X11 FORWARDING 976If the 977.Cm ForwardX11 978variable is set to 979.Dq yes 980(or see the description of the 981.Fl X , 982.Fl x , 983and 984.Fl Y 985options above) 986and the user is using X11 (the 987.Ev DISPLAY 988environment variable is set), the connection to the X11 display is 989automatically forwarded to the remote side in such a way that any X11 990programs started from the shell (or command) will go through the 991encrypted channel, and the connection to the real X server will be made 992from the local machine. 993The user should not manually set 994.Ev DISPLAY . 995Forwarding of X11 connections can be 996configured on the command line or in configuration files. 997.Pp 998The 999.Ev DISPLAY 1000value set by 1001.Nm 1002will point to the server machine, but with a display number greater than zero. 1003This is normal, and happens because 1004.Nm 1005creates a 1006.Dq proxy 1007X server on the server machine for forwarding the 1008connections over the encrypted channel. 1009.Pp 1010.Nm 1011will also automatically set up Xauthority data on the server machine. 1012For this purpose, it will generate a random authorization cookie, 1013store it in Xauthority on the server, and verify that any forwarded 1014connections carry this cookie and replace it by the real cookie when 1015the connection is opened. 1016The real authentication cookie is never 1017sent to the server machine (and no cookies are sent in the plain). 1018.Pp 1019If the 1020.Cm ForwardAgent 1021variable is set to 1022.Dq yes 1023(or see the description of the 1024.Fl A 1025and 1026.Fl a 1027options above) and 1028the user is using an authentication agent, the connection to the agent 1029is automatically forwarded to the remote side. 1030.Sh VERIFYING HOST KEYS 1031When connecting to a server for the first time, 1032a fingerprint of the server's public key is presented to the user 1033(unless the option 1034.Cm StrictHostKeyChecking 1035has been disabled). 1036Fingerprints can be determined using 1037.Xr ssh-keygen 1 : 1038.Pp 1039.Dl $ ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key 1040.Pp 1041If the fingerprint is already known, it can be matched 1042and the key can be accepted or rejected. 1043Because of the difficulty of comparing host keys 1044just by looking at hex strings, 1045there is also support to compare host keys visually, 1046using 1047.Em random art . 1048By setting the 1049.Cm VisualHostKey 1050option to 1051.Dq yes , 1052a small ASCII graphic gets displayed on every login to a server, no matter 1053if the session itself is interactive or not. 1054By learning the pattern a known server produces, a user can easily 1055find out that the host key has changed when a completely different pattern 1056is displayed. 1057Because these patterns are not unambiguous however, a pattern that looks 1058similar to the pattern remembered only gives a good probability that the 1059host key is the same, not guaranteed proof. 1060.Pp 1061To get a listing of the fingerprints along with their random art for 1062all known hosts, the following command line can be used: 1063.Pp 1064.Dl $ ssh-keygen -lv -f ~/.ssh/known_hosts 1065.Pp 1066If the fingerprint is unknown, 1067an alternative method of verification is available: 1068SSH fingerprints verified by DNS. 1069An additional resource record (RR), 1070SSHFP, 1071is added to a zonefile 1072and the connecting client is able to match the fingerprint 1073with that of the key presented. 1074.Pp 1075In this example, we are connecting a client to a server, 1076.Dq host.example.com . 1077The SSHFP resource records should first be added to the zonefile for 1078host.example.com: 1079.Bd -literal -offset indent 1080$ ssh-keygen -r host.example.com. 1081.Ed 1082.Pp 1083The output lines will have to be added to the zonefile. 1084To check that the zone is answering fingerprint queries: 1085.Pp 1086.Dl $ dig -t SSHFP host.example.com 1087.Pp 1088Finally the client connects: 1089.Bd -literal -offset indent 1090$ ssh -o "VerifyHostKeyDNS ask" host.example.com 1091[...] 1092Matching host key fingerprint found in DNS. 1093Are you sure you want to continue connecting (yes/no)? 1094.Ed 1095.Pp 1096See the 1097.Cm VerifyHostKeyDNS 1098option in 1099.Xr ssh_config 5 1100for more information. 1101.Sh SSH-BASED VIRTUAL PRIVATE NETWORKS 1102.Nm 1103contains support for Virtual Private Network (VPN) tunnelling 1104using the 1105.Xr tun 4 1106network pseudo-device, 1107allowing two networks to be joined securely. 1108The 1109.Xr sshd_config 5 1110configuration option 1111.Cm PermitTunnel 1112controls whether the server supports this, 1113and at what level (layer 2 or 3 traffic). 1114.Pp 1115The following example would connect client network 10.0.50.0/24 1116with remote network 10.0.99.0/24 using a point-to-point connection 1117from 10.1.1.1 to 10.1.1.2, 1118provided that the SSH server running on the gateway to the remote network, 1119at 192.168.1.15, allows it. 1120.Pp 1121On the client: 1122.Bd -literal -offset indent 1123# ssh -f -w 0:1 192.168.1.15 true 1124# ifconfig tun0 10.1.1.1 10.1.1.2 netmask 255.255.255.252 1125# route add 10.0.99.0/24 10.1.1.2 1126.Ed 1127.Pp 1128On the server: 1129.Bd -literal -offset indent 1130# ifconfig tun1 10.1.1.2 10.1.1.1 netmask 255.255.255.252 1131# route add 10.0.50.0/24 10.1.1.1 1132.Ed 1133.Pp 1134Client access may be more finely tuned via the 1135.Pa /root/.ssh/authorized_keys 1136file (see below) and the 1137.Cm PermitRootLogin 1138server option. 1139The following entry would permit connections on 1140.Xr tun 4 1141device 1 from user 1142.Dq jane 1143and on tun device 2 from user 1144.Dq john , 1145if 1146.Cm PermitRootLogin 1147is set to 1148.Dq forced-commands-only : 1149.Bd -literal -offset 2n 1150tunnel="1",command="sh /etc/netstart tun1" ssh-rsa ... jane 1151tunnel="2",command="sh /etc/netstart tun2" ssh-rsa ... john 1152.Ed 1153.Pp 1154Since an SSH-based setup entails a fair amount of overhead, 1155it may be more suited to temporary setups, 1156such as for wireless VPNs. 1157More permanent VPNs are better provided by tools such as 1158.Xr ipsecctl 8 1159and 1160.Xr isakmpd 8 . 1161.Sh ENVIRONMENT 1162.Nm 1163will normally set the following environment variables: 1164.Bl -tag -width "SSH_ORIGINAL_COMMAND" 1165.It Ev DISPLAY 1166The 1167.Ev DISPLAY 1168variable indicates the location of the X11 server. 1169It is automatically set by 1170.Nm 1171to point to a value of the form 1172.Dq hostname:n , 1173where 1174.Dq hostname 1175indicates the host where the shell runs, and 1176.Sq n 1177is an integer \*(Ge 1. 1178.Nm 1179uses this special value to forward X11 connections over the secure 1180channel. 1181The user should normally not set 1182.Ev DISPLAY 1183explicitly, as that 1184will render the X11 connection insecure (and will require the user to 1185manually copy any required authorization cookies). 1186.It Ev HOME 1187Set to the path of the user's home directory. 1188.It Ev LOGNAME 1189Synonym for 1190.Ev USER ; 1191set for compatibility with systems that use this variable. 1192.It Ev MAIL 1193Set to the path of the user's mailbox. 1194.It Ev PATH 1195Set to the default 1196.Ev PATH , 1197as specified when compiling 1198.Nm . 1199.It Ev SSH_ASKPASS 1200If 1201.Nm 1202needs a passphrase, it will read the passphrase from the current 1203terminal if it was run from a terminal. 1204If 1205.Nm 1206does not have a terminal associated with it but 1207.Ev DISPLAY 1208and 1209.Ev SSH_ASKPASS 1210are set, it will execute the program specified by 1211.Ev SSH_ASKPASS 1212and open an X11 window to read the passphrase. 1213This is particularly useful when calling 1214.Nm 1215from a 1216.Pa .xsession 1217or related script. 1218(Note that on some machines it 1219may be necessary to redirect the input from 1220.Pa /dev/null 1221to make this work.) 1222.It Ev SSH_AUTH_SOCK 1223Identifies the path of a 1224.Ux Ns -domain 1225socket used to communicate with the agent. 1226.It Ev SSH_CONNECTION 1227Identifies the client and server ends of the connection. 1228The variable contains 1229four space-separated values: client IP address, client port number, 1230server IP address, and server port number. 1231.It Ev SSH_ORIGINAL_COMMAND 1232This variable contains the original command line if a forced command 1233is executed. 1234It can be used to extract the original arguments. 1235.It Ev SSH_TTY 1236This is set to the name of the tty (path to the device) associated 1237with the current shell or command. 1238If the current session has no tty, 1239this variable is not set. 1240.It Ev TZ 1241This variable is set to indicate the present time zone if it 1242was set when the daemon was started (i.e. the daemon passes the value 1243on to new connections). 1244.It Ev USER 1245Set to the name of the user logging in. 1246.El 1247.Pp 1248Additionally, 1249.Nm 1250reads 1251.Pa ~/.ssh/environment , 1252and adds lines of the format 1253.Dq VARNAME=value 1254to the environment if the file exists and users are allowed to 1255change their environment. 1256For more information, see the 1257.Cm PermitUserEnvironment 1258option in 1259.Xr sshd_config 5 . 1260.Sh FILES 1261.Bl -tag -width Ds -compact 1262.It Pa ~/.rhosts 1263This file is used for host-based authentication (see above). 1264On some machines this file may need to be 1265world-readable if the user's home directory is on an NFS partition, 1266because 1267.Xr sshd 8 1268reads it as root. 1269Additionally, this file must be owned by the user, 1270and must not have write permissions for anyone else. 1271The recommended 1272permission for most machines is read/write for the user, and not 1273accessible by others. 1274.Pp 1275.It Pa ~/.shosts 1276This file is used in exactly the same way as 1277.Pa .rhosts , 1278but allows host-based authentication without permitting login with 1279rlogin/rsh. 1280.Pp 1281.It Pa ~/.ssh/ 1282This directory is the default location for all user-specific configuration 1283and authentication information. 1284There is no general requirement to keep the entire contents of this directory 1285secret, but the recommended permissions are read/write/execute for the user, 1286and not accessible by others. 1287.Pp 1288.It Pa ~/.ssh/authorized_keys 1289Lists the public keys (DSA/ECDSA/RSA) that can be used for logging in as 1290this user. 1291The format of this file is described in the 1292.Xr sshd 8 1293manual page. 1294This file is not highly sensitive, but the recommended 1295permissions are read/write for the user, and not accessible by others. 1296.Pp 1297.It Pa ~/.ssh/config 1298This is the per-user configuration file. 1299The file format and configuration options are described in 1300.Xr ssh_config 5 . 1301Because of the potential for abuse, this file must have strict permissions: 1302read/write for the user, and not accessible by others. 1303.Pp 1304.It Pa ~/.ssh/environment 1305Contains additional definitions for environment variables; see 1306.Sx ENVIRONMENT , 1307above. 1308.Pp 1309.It Pa ~/.ssh/identity 1310.It Pa ~/.ssh/id_dsa 1311.It Pa ~/.ssh/id_ecdsa 1312.It Pa ~/.ssh/id_rsa 1313Contains the private key for authentication. 1314These files 1315contain sensitive data and should be readable by the user but not 1316accessible by others (read/write/execute). 1317.Nm 1318will simply ignore a private key file if it is accessible by others. 1319It is possible to specify a passphrase when 1320generating the key which will be used to encrypt the 1321sensitive part of this file using 3DES. 1322.Pp 1323.It Pa ~/.ssh/identity.pub 1324.It Pa ~/.ssh/id_dsa.pub 1325.It Pa ~/.ssh/id_ecdsa.pub 1326.It Pa ~/.ssh/id_rsa.pub 1327Contains the public key for authentication. 1328These files are not 1329sensitive and can (but need not) be readable by anyone. 1330.Pp 1331.It Pa ~/.ssh/known_hosts 1332Contains a list of host keys for all hosts the user has logged into 1333that are not already in the systemwide list of known host keys. 1334See 1335.Xr sshd 8 1336for further details of the format of this file. 1337.Pp 1338.It Pa ~/.ssh/rc 1339Commands in this file are executed by 1340.Nm 1341when the user logs in, just before the user's shell (or command) is 1342started. 1343See the 1344.Xr sshd 8 1345manual page for more information. 1346.Pp 1347.It Pa /etc/hosts.equiv 1348This file is for host-based authentication (see above). 1349It should only be writable by root. 1350.Pp 1351.It Pa /etc/shosts.equiv 1352This file is used in exactly the same way as 1353.Pa hosts.equiv , 1354but allows host-based authentication without permitting login with 1355rlogin/rsh. 1356.Pp 1357.It Pa /etc/ssh/ssh_config 1358Systemwide configuration file. 1359The file format and configuration options are described in 1360.Xr ssh_config 5 . 1361.Pp 1362.It Pa /etc/ssh/ssh_host_key 1363.It Pa /etc/ssh/ssh_host_dsa_key 1364.It Pa /etc/ssh/ssh_host_ecdsa_key 1365.It Pa /etc/ssh/ssh_host_rsa_key 1366These three files contain the private parts of the host keys 1367and are used for host-based authentication. 1368If protocol version 1 is used, 1369.Nm 1370must be setuid root, since the host key is readable only by root. 1371For protocol version 2, 1372.Nm 1373uses 1374.Xr ssh-keysign 8 1375to access the host keys, 1376eliminating the requirement that 1377.Nm 1378be setuid root when host-based authentication is used. 1379By default 1380.Nm 1381is not setuid root. 1382.Pp 1383.It Pa /etc/ssh/ssh_known_hosts 1384Systemwide list of known host keys. 1385This file should be prepared by the 1386system administrator to contain the public host keys of all machines in the 1387organization. 1388It should be world-readable. 1389See 1390.Xr sshd 8 1391for further details of the format of this file. 1392.Pp 1393.It Pa /etc/ssh/sshrc 1394Commands in this file are executed by 1395.Nm 1396when the user logs in, just before the user's shell (or command) is started. 1397See the 1398.Xr sshd 8 1399manual page for more information. 1400.El 1401.Sh EXIT STATUS 1402.Nm 1403exits with the exit status of the remote command or with 255 1404if an error occurred. 1405.Sh SEE ALSO 1406.Xr scp 1 , 1407.Xr sftp 1 , 1408.Xr ssh-add 1 , 1409.Xr ssh-agent 1 , 1410.Xr ssh-keygen 1 , 1411.Xr ssh-keyscan 1 , 1412.Xr tun 4 , 1413.Xr hosts.equiv 5 , 1414.Xr ssh_config 5 , 1415.Xr ssh-keysign 8 , 1416.Xr sshd 8 1417.Rs 1418.%R RFC 4250 1419.%T "The Secure Shell (SSH) Protocol Assigned Numbers" 1420.%D 2006 1421.Re 1422.Rs 1423.%R RFC 4251 1424.%T "The Secure Shell (SSH) Protocol Architecture" 1425.%D 2006 1426.Re 1427.Rs 1428.%R RFC 4252 1429.%T "The Secure Shell (SSH) Authentication Protocol" 1430.%D 2006 1431.Re 1432.Rs 1433.%R RFC 4253 1434.%T "The Secure Shell (SSH) Transport Layer Protocol" 1435.%D 2006 1436.Re 1437.Rs 1438.%R RFC 4254 1439.%T "The Secure Shell (SSH) Connection Protocol" 1440.%D 2006 1441.Re 1442.Rs 1443.%R RFC 4255 1444.%T "Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints" 1445.%D 2006 1446.Re 1447.Rs 1448.%R RFC 4256 1449.%T "Generic Message Exchange Authentication for the Secure Shell Protocol (SSH)" 1450.%D 2006 1451.Re 1452.Rs 1453.%R RFC 4335 1454.%T "The Secure Shell (SSH) Session Channel Break Extension" 1455.%D 2006 1456.Re 1457.Rs 1458.%R RFC 4344 1459.%T "The Secure Shell (SSH) Transport Layer Encryption Modes" 1460.%D 2006 1461.Re 1462.Rs 1463.%R RFC 4345 1464.%T "Improved Arcfour Modes for the Secure Shell (SSH) Transport Layer Protocol" 1465.%D 2006 1466.Re 1467.Rs 1468.%R RFC 4419 1469.%T "Diffie-Hellman Group Exchange for the Secure Shell (SSH) Transport Layer Protocol" 1470.%D 2006 1471.Re 1472.Rs 1473.%R RFC 4716 1474.%T "The Secure Shell (SSH) Public Key File Format" 1475.%D 2006 1476.Re 1477.Rs 1478.%R RFC 5656 1479.%T "Elliptic Curve Algorithm Integration in the Secure Shell Transport Layer" 1480.%D 2009 1481.Re 1482.Rs 1483.%T "Hash Visualization: a New Technique to improve Real-World Security" 1484.%A A. Perrig 1485.%A D. Song 1486.%D 1999 1487.%O "International Workshop on Cryptographic Techniques and E-Commerce (CrypTEC '99)" 1488.Re 1489.Sh AUTHORS 1490OpenSSH is a derivative of the original and free 1491ssh 1.2.12 release by Tatu Ylonen. 1492Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, 1493Theo de Raadt and Dug Song 1494removed many bugs, re-added newer features and 1495created OpenSSH. 1496Markus Friedl contributed the support for SSH 1497protocol versions 1.5 and 2.0. 1498