1 SSH(1) General Commands Manual SSH(1) 2 3 NAME 4 ssh M-bM-^@M-^S OpenSSH SSH client (remote login program) 5 6 SYNOPSIS 7 ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] 8 [-D [bind_address:]port] [-E log_file] [-e escape_char] 9 [-F configfile] [-I pkcs11] [-i identity_file] [-L address] 10 [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] 11 [-Q cipher | cipher-auth | mac | kex | key | protocol-version] 12 [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] 13 [user@]hostname [command] 14 15 DESCRIPTION 16 ssh (SSH client) is a program for logging into a remote machine and for 17 executing commands on a remote machine. It is intended to replace rlogin 18 and rsh, and provide secure encrypted communications between two 19 untrusted hosts over an insecure network. X11 connections, arbitrary TCP 20 ports and UNIX-domain sockets can also be forwarded over the secure 21 channel. 22 23 ssh connects and logs into the specified hostname (with optional user 24 name). The user must prove his/her identity to the remote machine using 25 one of several methods depending on the protocol version used (see 26 below). 27 28 If command is specified, it is executed on the remote host instead of a 29 login shell. 30 31 The options are as follows: 32 33 -1 Forces ssh to try protocol version 1 only. 34 35 -2 Forces ssh to try protocol version 2 only. 36 37 -4 Forces ssh to use IPv4 addresses only. 38 39 -6 Forces ssh to use IPv6 addresses only. 40 41 -A Enables forwarding of the authentication agent connection. This 42 can also be specified on a per-host basis in a configuration 43 file. 44 45 Agent forwarding should be enabled with caution. Users with the 46 ability to bypass file permissions on the remote host (for the 47 agent's UNIX-domain socket) can access the local agent through 48 the forwarded connection. An attacker cannot obtain key material 49 from the agent, however they can perform operations on the keys 50 that enable them to authenticate using the identities loaded into 51 the agent. 52 53 -a Disables forwarding of the authentication agent connection. 54 55 -b bind_address 56 Use bind_address on the local machine as the source address of 57 the connection. Only useful on systems with more than one 58 address. 59 60 -C Requests compression of all data (including stdin, stdout, 61 stderr, and data for forwarded X11, TCP and UNIX-domain 62 connections). The compression algorithm is the same used by 63 gzip(1), and the M-bM-^@M-^\levelM-bM-^@M-^] can be controlled by the 64 CompressionLevel option for protocol version 1. Compression is 65 desirable on modem lines and other slow connections, but will 66 only slow down things on fast networks. The default value can be 67 set on a host-by-host basis in the configuration files; see the 68 Compression option. 69 70 -c cipher_spec 71 Selects the cipher specification for encrypting the session. 72 73 Protocol version 1 allows specification of a single cipher. The 74 supported values are M-bM-^@M-^\3desM-bM-^@M-^], M-bM-^@M-^\blowfishM-bM-^@M-^], and M-bM-^@M-^\desM-bM-^@M-^]. For protocol 75 version 2, cipher_spec is a comma-separated list of ciphers 76 listed in order of preference. See the Ciphers keyword in 77 ssh_config(5) for more information. 78 79 -D [bind_address:]port 80 Specifies a local M-bM-^@M-^\dynamicM-bM-^@M-^] application-level port forwarding. 81 This works by allocating a socket to listen to port on the local 82 side, optionally bound to the specified bind_address. Whenever a 83 connection is made to this port, the connection is forwarded over 84 the secure channel, and the application protocol is then used to 85 determine where to connect to from the remote machine. Currently 86 the SOCKS4 and SOCKS5 protocols are supported, and ssh will act 87 as a SOCKS server. Only root can forward privileged ports. 88 Dynamic port forwardings can also be specified in the 89 configuration file. 90 91 IPv6 addresses can be specified by enclosing the address in 92 square brackets. Only the superuser can forward privileged 93 ports. By default, the local port is bound in accordance with 94 the GatewayPorts setting. However, an explicit bind_address may 95 be used to bind the connection to a specific address. The 96 bind_address of M-bM-^@M-^\localhostM-bM-^@M-^] indicates that the listening port be 97 bound for local use only, while an empty address or M-bM-^@M-^X*M-bM-^@M-^Y indicates 98 that the port should be available from all interfaces. 99 100 -E log_file 101 Append debug logs to log_file instead of standard error. 102 103 -e escape_char 104 Sets the escape character for sessions with a pty (default: M-bM-^@M-^X~M-bM-^@M-^Y). 105 The escape character is only recognized at the beginning of a 106 line. The escape character followed by a dot (M-bM-^@M-^X.M-bM-^@M-^Y) closes the 107 connection; followed by control-Z suspends the connection; and 108 followed by itself sends the escape character once. Setting the 109 character to M-bM-^@M-^\noneM-bM-^@M-^] disables any escapes and makes the session 110 fully transparent. 111 112 -F configfile 113 Specifies an alternative per-user configuration file. If a 114 configuration file is given on the command line, the system-wide 115 configuration file (/etc/ssh/ssh_config) will be ignored. The 116 default for the per-user configuration file is ~/.ssh/config. 117 118 -f Requests ssh to go to background just before command execution. 119 This is useful if ssh is going to ask for passwords or 120 passphrases, but the user wants it in the background. This 121 implies -n. The recommended way to start X11 programs at a 122 remote site is with something like ssh -f host xterm. 123 124 If the ExitOnForwardFailure configuration option is set to M-bM-^@M-^\yesM-bM-^@M-^], 125 then a client started with -f will wait for all remote port 126 forwards to be successfully established before placing itself in 127 the background. 128 129 -G Causes ssh to print its configuration after evaluating Host and 130 Match blocks and exit. 131 132 -g Allows remote hosts to connect to local forwarded ports. If used 133 on a multiplexed connection, then this option must be specified 134 on the master process. 135 136 -I pkcs11 137 Specify the PKCS#11 shared library ssh should use to communicate 138 with a PKCS#11 token providing the user's private RSA key. 139 140 -i identity_file 141 Selects a file from which the identity (private key) for public 142 key authentication is read. The default is ~/.ssh/identity for 143 protocol version 1, and ~/.ssh/id_dsa, ~/.ssh/id_ecdsa, 144 ~/.ssh/id_ed25519 and ~/.ssh/id_rsa for protocol version 2. 145 Identity files may also be specified on a per-host basis in the 146 configuration file. It is possible to have multiple -i options 147 (and multiple identities specified in configuration files). ssh 148 will also try to load certificate information from the filename 149 obtained by appending -cert.pub to identity filenames. 150 151 -K Enables GSSAPI-based authentication and forwarding (delegation) 152 of GSSAPI credentials to the server. 153 154 -k Disables forwarding (delegation) of GSSAPI credentials to the 155 server. 156 157 -L [bind_address:]port:host:hostport 158 -L [bind_address:]port:remote_socket 159 -L local_socket:host:hostport 160 -L local_socket:remote_socket 161 Specifies that connections to the given TCP port or Unix socket 162 on the local (client) host are to be forwarded to the given host 163 and port, or Unix socket, on the remote side. This works by 164 allocating a socket to listen to either a TCP port on the local 165 side, optionally bound to the specified bind_address, or to a 166 Unix socket. Whenever a connection is made to the local port or 167 socket, the connection is forwarded over the secure channel, and 168 a connection is made to either host port hostport, or the Unix 169 socket remote_socket, from the remote machine. 170 171 Port forwardings can also be specified in the configuration file. 172 Only the superuser can forward privileged ports. IPv6 addresses 173 can be specified by enclosing the address in square brackets. 174 175 By default, the local port is bound in accordance with the 176 GatewayPorts setting. However, an explicit bind_address may be 177 used to bind the connection to a specific address. The 178 bind_address of M-bM-^@M-^\localhostM-bM-^@M-^] indicates that the listening port be 179 bound for local use only, while an empty address or M-bM-^@M-^X*M-bM-^@M-^Y indicates 180 that the port should be available from all interfaces. 181 182 -l login_name 183 Specifies the user to log in as on the remote machine. This also 184 may be specified on a per-host basis in the configuration file. 185 186 -M Places the ssh client into M-bM-^@M-^\masterM-bM-^@M-^] mode for connection sharing. 187 Multiple -M options places ssh into M-bM-^@M-^\masterM-bM-^@M-^] mode with 188 confirmation required before slave connections are accepted. 189 Refer to the description of ControlMaster in ssh_config(5) for 190 details. 191 192 -m mac_spec 193 Additionally, for protocol version 2 a comma-separated list of 194 MAC (message authentication code) algorithms can be specified in 195 order of preference. See the MACs keyword for more information. 196 197 -N Do not execute a remote command. This is useful for just 198 forwarding ports (protocol version 2 only). 199 200 -n Redirects stdin from /dev/null (actually, prevents reading from 201 stdin). This must be used when ssh is run in the background. A 202 common trick is to use this to run X11 programs on a remote 203 machine. For example, ssh -n shadows.cs.hut.fi emacs & will 204 start an emacs on shadows.cs.hut.fi, and the X11 connection will 205 be automatically forwarded over an encrypted channel. The ssh 206 program will be put in the background. (This does not work if 207 ssh needs to ask for a password or passphrase; see also the -f 208 option.) 209 210 -O ctl_cmd 211 Control an active connection multiplexing master process. When 212 the -O option is specified, the ctl_cmd argument is interpreted 213 and passed to the master process. Valid commands are: M-bM-^@M-^\checkM-bM-^@M-^] 214 (check that the master process is running), M-bM-^@M-^\forwardM-bM-^@M-^] (request 215 forwardings without command execution), M-bM-^@M-^\cancelM-bM-^@M-^] (cancel 216 forwardings), M-bM-^@M-^\exitM-bM-^@M-^] (request the master to exit), and M-bM-^@M-^\stopM-bM-^@M-^] 217 (request the master to stop accepting further multiplexing 218 requests). 219 220 -o option 221 Can be used to give options in the format used in the 222 configuration file. This is useful for specifying options for 223 which there is no separate command-line flag. For full details 224 of the options listed below, and their possible values, see 225 ssh_config(5). 226 227 AddressFamily 228 BatchMode 229 BindAddress 230 CanonicalDomains 231 CanonicalizeFallbackLocal 232 CanonicalizeHostname 233 CanonicalizeMaxDots 234 CanonicalizePermittedCNAMEs 235 ChallengeResponseAuthentication 236 CheckHostIP 237 Cipher 238 Ciphers 239 ClearAllForwardings 240 Compression 241 CompressionLevel 242 ConnectionAttempts 243 ConnectTimeout 244 ControlMaster 245 ControlPath 246 ControlPersist 247 DynamicForward 248 EscapeChar 249 ExitOnForwardFailure 250 FingerprintHash 251 ForwardAgent 252 ForwardX11 253 ForwardX11Timeout 254 ForwardX11Trusted 255 GatewayPorts 256 GlobalKnownHostsFile 257 GSSAPIAuthentication 258 GSSAPIDelegateCredentials 259 HashKnownHosts 260 Host 261 HostbasedAuthentication 262 HostbasedKeyTypes 263 HostKeyAlgorithms 264 HostKeyAlias 265 HostName 266 IdentityFile 267 IdentitiesOnly 268 IPQoS 269 KbdInteractiveAuthentication 270 KbdInteractiveDevices 271 KexAlgorithms 272 LocalCommand 273 LocalForward 274 LogLevel 275 MACs 276 Match 277 NoHostAuthenticationForLocalhost 278 NumberOfPasswordPrompts 279 PasswordAuthentication 280 PermitLocalCommand 281 PKCS11Provider 282 Port 283 PreferredAuthentications 284 Protocol 285 ProxyCommand 286 ProxyUseFdpass 287 PubkeyAcceptedKeyTypes 288 PubkeyAuthentication 289 RekeyLimit 290 RemoteForward 291 RequestTTY 292 RhostsRSAAuthentication 293 RSAAuthentication 294 SendEnv 295 ServerAliveInterval 296 ServerAliveCountMax 297 StreamLocalBindMask 298 StreamLocalBindUnlink 299 StrictHostKeyChecking 300 TCPKeepAlive 301 Tunnel 302 TunnelDevice 303 UpdateHostKeys 304 UsePrivilegedPort 305 User 306 UserKnownHostsFile 307 VerifyHostKeyDNS 308 VisualHostKey 309 XAuthLocation 310 311 -p port 312 Port to connect to on the remote host. This can be specified on 313 a per-host basis in the configuration file. 314 315 -Q cipher | cipher-auth | mac | kex | key | protocol-version 316 Queries ssh for the algorithms supported for the specified 317 version 2. The available features are: cipher (supported 318 symmetric ciphers), cipher-auth (supported symmetric ciphers that 319 support authenticated encryption), mac (supported message 320 integrity codes), kex (key exchange algorithms), key (key types) 321 and protocol-version (supported SSH protocol versions). 322 323 -q Quiet mode. Causes most warning and diagnostic messages to be 324 suppressed. 325 326 -R [bind_address:]port:host:hostport 327 -R [bind_address:]port:local_socket 328 -R remote_socket:host:hostport 329 -R remote_socket:local_socket 330 Specifies that connections to the given TCP port or Unix socket 331 on the remote (server) host are to be forwarded to the given host 332 and port, or Unix socket, on the local side. This works by 333 allocating a socket to listen to either a TCP port or to a Unix 334 socket on the remote side. Whenever a connection is made to this 335 port or Unix socket, the connection is forwarded over the secure 336 channel, and a connection is made to either host port hostport, 337 or local_socket, from the local machine. 338 339 Port forwardings can also be specified in the configuration file. 340 Privileged ports can be forwarded only when logging in as root on 341 the remote machine. IPv6 addresses can be specified by enclosing 342 the address in square brackets. 343 344 By default, TCP listening sockets on the server will be bound to 345 the loopback interface only. This may be overridden by 346 specifying a bind_address. An empty bind_address, or the address 347 M-bM-^@M-^X*M-bM-^@M-^Y, indicates that the remote socket should listen on all 348 interfaces. Specifying a remote bind_address will only succeed 349 if the server's GatewayPorts option is enabled (see 350 sshd_config(5)). 351 352 If the port argument is M-bM-^@M-^X0M-bM-^@M-^Y, the listen port will be dynamically 353 allocated on the server and reported to the client at run time. 354 When used together with -O forward the allocated port will be 355 printed to the standard output. 356 357 -S ctl_path 358 Specifies the location of a control socket for connection 359 sharing, or the string M-bM-^@M-^\noneM-bM-^@M-^] to disable connection sharing. 360 Refer to the description of ControlPath and ControlMaster in 361 ssh_config(5) for details. 362 363 -s May be used to request invocation of a subsystem on the remote 364 system. Subsystems are a feature of the SSH2 protocol which 365 facilitate the use of SSH as a secure transport for other 366 applications (eg. sftp(1)). The subsystem is specified as the 367 remote command. 368 369 -T Disable pseudo-terminal allocation. 370 371 -t Force pseudo-terminal allocation. This can be used to execute 372 arbitrary screen-based programs on a remote machine, which can be 373 very useful, e.g. when implementing menu services. Multiple -t 374 options force tty allocation, even if ssh has no local tty. 375 376 -V Display the version number and exit. 377 378 -v Verbose mode. Causes ssh to print debugging messages about its 379 progress. This is helpful in debugging connection, 380 authentication, and configuration problems. Multiple -v options 381 increase the verbosity. The maximum is 3. 382 383 -W host:port 384 Requests that standard input and output on the client be 385 forwarded to host on port over the secure channel. Implies -N, 386 -T, ExitOnForwardFailure and ClearAllForwardings. Works with 387 Protocol version 2 only. 388 389 -w local_tun[:remote_tun] 390 Requests tunnel device forwarding with the specified tun(4) 391 devices between the client (local_tun) and the server 392 (remote_tun). 393 394 The devices may be specified by numerical ID or the keyword 395 M-bM-^@M-^\anyM-bM-^@M-^], which uses the next available tunnel device. If 396 remote_tun is not specified, it defaults to M-bM-^@M-^\anyM-bM-^@M-^]. See also the 397 Tunnel and TunnelDevice directives in ssh_config(5). If the 398 Tunnel directive is unset, it is set to the default tunnel mode, 399 which is M-bM-^@M-^\point-to-pointM-bM-^@M-^]. 400 401 -X Enables X11 forwarding. This can also be specified on a per-host 402 basis in a configuration file. 403 404 X11 forwarding should be enabled with caution. Users with the 405 ability to bypass file permissions on the remote host (for the 406 user's X authorization database) can access the local X11 display 407 through the forwarded connection. An attacker may then be able 408 to perform activities such as keystroke monitoring. 409 410 For this reason, X11 forwarding is subjected to X11 SECURITY 411 extension restrictions by default. Please refer to the ssh -Y 412 option and the ForwardX11Trusted directive in ssh_config(5) for 413 more information. 414 415 -x Disables X11 forwarding. 416 417 -Y Enables trusted X11 forwarding. Trusted X11 forwardings are not 418 subjected to the X11 SECURITY extension controls. 419 420 -y Send log information using the syslog(3) system module. By 421 default this information is sent to stderr. 422 423 ssh may additionally obtain configuration data from a per-user 424 configuration file and a system-wide configuration file. The file format 425 and configuration options are described in ssh_config(5). 426 427 AUTHENTICATION 428 The OpenSSH SSH client supports SSH protocols 1 and 2. The default is to 429 use protocol 2 only, though this can be changed via the Protocol option 430 in ssh_config(5) or the -1 and -2 options (see above). Both protocols 431 support similar authentication methods, but protocol 2 is the default 432 since it provides additional mechanisms for confidentiality (the traffic 433 is encrypted using AES, 3DES, Blowfish, CAST128, or Arcfour) and 434 integrity (hmac-md5, hmac-sha1, hmac-sha2-256, hmac-sha2-512, umac-64, 435 umac-128, hmac-ripemd160). Protocol 1 lacks a strong mechanism for 436 ensuring the integrity of the connection. 437 438 The methods available for authentication are: GSSAPI-based 439 authentication, host-based authentication, public key authentication, 440 challenge-response authentication, and password authentication. 441 Authentication methods are tried in the order specified above, though 442 protocol 2 has a configuration option to change the default order: 443 PreferredAuthentications. 444 445 Host-based authentication works as follows: If the machine the user logs 446 in from is listed in /etc/hosts.equiv or /etc/shosts.equiv on the remote 447 machine, and the user names are the same on both sides, or if the files 448 ~/.rhosts or ~/.shosts exist in the user's home directory on the remote 449 machine and contain a line containing the name of the client machine and 450 the name of the user on that machine, the user is considered for login. 451 Additionally, the server must be able to verify the client's host key 452 (see the description of /etc/ssh/ssh_known_hosts and ~/.ssh/known_hosts, 453 below) for login to be permitted. This authentication method closes 454 security holes due to IP spoofing, DNS spoofing, and routing spoofing. 455 [Note to the administrator: /etc/hosts.equiv, ~/.rhosts, and the 456 rlogin/rsh protocol in general, are inherently insecure and should be 457 disabled if security is desired.] 458 459 Public key authentication works as follows: The scheme is based on 460 public-key cryptography, using cryptosystems where encryption and 461 decryption are done using separate keys, and it is unfeasible to derive 462 the decryption key from the encryption key. The idea is that each user 463 creates a public/private key pair for authentication purposes. The 464 server knows the public key, and only the user knows the private key. 465 ssh implements public key authentication protocol automatically, using 466 one of the DSA, ECDSA, Ed25519 or RSA algorithms. Protocol 1 is 467 restricted to using only RSA keys, but protocol 2 may use any. The 468 HISTORY section of ssl(8) contains a brief discussion of the DSA and RSA 469 algorithms. 470 471 The file ~/.ssh/authorized_keys lists the public keys that are permitted 472 for logging in. When the user logs in, the ssh program tells the server 473 which key pair it would like to use for authentication. The client 474 proves that it has access to the private key and the server checks that 475 the corresponding public key is authorized to accept the account. 476 477 The user creates his/her key pair by running ssh-keygen(1). This stores 478 the private key in ~/.ssh/identity (protocol 1), ~/.ssh/id_dsa (protocol 479 2 DSA), ~/.ssh/id_ecdsa (protocol 2 ECDSA), ~/.ssh/id_ed25519 (protocol 2 480 Ed25519), or ~/.ssh/id_rsa (protocol 2 RSA) and stores the public key in 481 ~/.ssh/identity.pub (protocol 1), ~/.ssh/id_dsa.pub (protocol 2 DSA), 482 ~/.ssh/id_ecdsa.pub (protocol 2 ECDSA), ~/.ssh/id_ed25519.pub (protocol 2 483 Ed25519), or ~/.ssh/id_rsa.pub (protocol 2 RSA) in the user's home 484 directory. The user should then copy the public key to 485 ~/.ssh/authorized_keys in his/her home directory on the remote machine. 486 The authorized_keys file corresponds to the conventional ~/.rhosts file, 487 and has one key per line, though the lines can be very long. After this, 488 the user can log in without giving the password. 489 490 A variation on public key authentication is available in the form of 491 certificate authentication: instead of a set of public/private keys, 492 signed certificates are used. This has the advantage that a single 493 trusted certification authority can be used in place of many 494 public/private keys. See the CERTIFICATES section of ssh-keygen(1) for 495 more information. 496 497 The most convenient way to use public key or certificate authentication 498 may be with an authentication agent. See ssh-agent(1) for more 499 information. 500 501 Challenge-response authentication works as follows: The server sends an 502 arbitrary "challenge" text, and prompts for a response. Protocol 2 503 allows multiple challenges and responses; protocol 1 is restricted to 504 just one challenge/response. Examples of challenge-response 505 authentication include BSD Authentication (see login.conf(5)) and PAM 506 (some non-OpenBSD systems). 507 508 Finally, if other authentication methods fail, ssh prompts the user for a 509 password. The password is sent to the remote host for checking; however, 510 since all communications are encrypted, the password cannot be seen by 511 someone listening on the network. 512 513 ssh automatically maintains and checks a database containing 514 identification for all hosts it has ever been used with. Host keys are 515 stored in ~/.ssh/known_hosts in the user's home directory. Additionally, 516 the file /etc/ssh/ssh_known_hosts is automatically checked for known 517 hosts. Any new hosts are automatically added to the user's file. If a 518 host's identification ever changes, ssh warns about this and disables 519 password authentication to prevent server spoofing or man-in-the-middle 520 attacks, which could otherwise be used to circumvent the encryption. The 521 StrictHostKeyChecking option can be used to control logins to machines 522 whose host key is not known or has changed. 523 524 When the user's identity has been accepted by the server, the server 525 either executes the given command in a non-interactive session or, if no 526 command has been specified, logs into the machine and gives the user a 527 normal shell as an interactive session. All communication with the 528 remote command or shell will be automatically encrypted. 529 530 If an interactive session is requested ssh by default will only request a 531 pseudo-terminal (pty) for interactive sessions when the client has one. 532 The flags -T and -t can be used to override this behaviour. 533 534 If a pseudo-terminal has been allocated the user may use the escape 535 characters noted below. 536 537 If no pseudo-terminal has been allocated, the session is transparent and 538 can be used to reliably transfer binary data. On most systems, setting 539 the escape character to M-bM-^@M-^\noneM-bM-^@M-^] will also make the session transparent 540 even if a tty is used. 541 542 The session terminates when the command or shell on the remote machine 543 exits and all X11 and TCP connections have been closed. 544 545 ESCAPE CHARACTERS 546 When a pseudo-terminal has been requested, ssh supports a number of 547 functions through the use of an escape character. 548 549 A single tilde character can be sent as ~~ or by following the tilde by a 550 character other than those described below. The escape character must 551 always follow a newline to be interpreted as special. The escape 552 character can be changed in configuration files using the EscapeChar 553 configuration directive or on the command line by the -e option. 554 555 The supported escapes (assuming the default M-bM-^@M-^X~M-bM-^@M-^Y) are: 556 557 ~. Disconnect. 558 559 ~^Z Background ssh. 560 561 ~# List forwarded connections. 562 563 ~& Background ssh at logout when waiting for forwarded connection / 564 X11 sessions to terminate. 565 566 ~? Display a list of escape characters. 567 568 ~B Send a BREAK to the remote system (only useful for SSH protocol 569 version 2 and if the peer supports it). 570 571 ~C Open command line. Currently this allows the addition of port 572 forwardings using the -L, -R and -D options (see above). It also 573 allows the cancellation of existing port-forwardings with 574 -KL[bind_address:]port for local, -KR[bind_address:]port for 575 remote and -KD[bind_address:]port for dynamic port-forwardings. 576 !command allows the user to execute a local command if the 577 PermitLocalCommand option is enabled in ssh_config(5). Basic 578 help is available, using the -h option. 579 580 ~R Request rekeying of the connection (only useful for SSH protocol 581 version 2 and if the peer supports it). 582 583 ~V Decrease the verbosity (LogLevel) when errors are being written 584 to stderr. 585 586 ~v Increase the verbosity (LogLevel) when errors are being written 587 to stderr. 588 589 TCP FORWARDING 590 Forwarding of arbitrary TCP connections over the secure channel can be 591 specified either on the command line or in a configuration file. One 592 possible application of TCP forwarding is a secure connection to a mail 593 server; another is going through firewalls. 594 595 In the example below, we look at encrypting communication between an IRC 596 client and server, even though the IRC server does not directly support 597 encrypted communications. This works as follows: the user connects to 598 the remote host using ssh, specifying a port to be used to forward 599 connections to the remote server. After that it is possible to start the 600 service which is to be encrypted on the client machine, connecting to the 601 same local port, and ssh will encrypt and forward the connection. 602 603 The following example tunnels an IRC session from client machine 604 M-bM-^@M-^\127.0.0.1M-bM-^@M-^] (localhost) to remote server M-bM-^@M-^\server.example.comM-bM-^@M-^]: 605 606 $ ssh -f -L 1234:localhost:6667 server.example.com sleep 10 607 $ irc -c '#users' -p 1234 pinky 127.0.0.1 608 609 This tunnels a connection to IRC server M-bM-^@M-^\server.example.comM-bM-^@M-^], joining 610 channel M-bM-^@M-^\#usersM-bM-^@M-^], nickname M-bM-^@M-^\pinkyM-bM-^@M-^], using port 1234. It doesn't matter 611 which port is used, as long as it's greater than 1023 (remember, only 612 root can open sockets on privileged ports) and doesn't conflict with any 613 ports already in use. The connection is forwarded to port 6667 on the 614 remote server, since that's the standard port for IRC services. 615 616 The -f option backgrounds ssh and the remote command M-bM-^@M-^\sleep 10M-bM-^@M-^] is 617 specified to allow an amount of time (10 seconds, in the example) to 618 start the service which is to be tunnelled. If no connections are made 619 within the time specified, ssh will exit. 620 621 X11 FORWARDING 622 If the ForwardX11 variable is set to M-bM-^@M-^\yesM-bM-^@M-^] (or see the description of the 623 -X, -x, and -Y options above) and the user is using X11 (the DISPLAY 624 environment variable is set), the connection to the X11 display is 625 automatically forwarded to the remote side in such a way that any X11 626 programs started from the shell (or command) will go through the 627 encrypted channel, and the connection to the real X server will be made 628 from the local machine. The user should not manually set DISPLAY. 629 Forwarding of X11 connections can be configured on the command line or in 630 configuration files. 631 632 The DISPLAY value set by ssh will point to the server machine, but with a 633 display number greater than zero. This is normal, and happens because 634 ssh creates a M-bM-^@M-^\proxyM-bM-^@M-^] X server on the server machine for forwarding the 635 connections over the encrypted channel. 636 637 ssh will also automatically set up Xauthority data on the server machine. 638 For this purpose, it will generate a random authorization cookie, store 639 it in Xauthority on the server, and verify that any forwarded connections 640 carry this cookie and replace it by the real cookie when the connection 641 is opened. The real authentication cookie is never sent to the server 642 machine (and no cookies are sent in the plain). 643 644 If the ForwardAgent variable is set to M-bM-^@M-^\yesM-bM-^@M-^] (or see the description of 645 the -A and -a options above) and the user is using an authentication 646 agent, the connection to the agent is automatically forwarded to the 647 remote side. 648 649 VERIFYING HOST KEYS 650 When connecting to a server for the first time, a fingerprint of the 651 server's public key is presented to the user (unless the option 652 StrictHostKeyChecking has been disabled). Fingerprints can be determined 653 using ssh-keygen(1): 654 655 $ ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key 656 657 If the fingerprint is already known, it can be matched and the key can be 658 accepted or rejected. If only legacy (MD5) fingerprints for the server 659 are available, the ssh-keygen(1) -E option may be used to downgrade the 660 fingerprint algorithm to match. 661 662 Because of the difficulty of comparing host keys just by looking at 663 fingerprint strings, there is also support to compare host keys visually, 664 using random art. By setting the VisualHostKey option to M-bM-^@M-^\yesM-bM-^@M-^], a small 665 ASCII graphic gets displayed on every login to a server, no matter if the 666 session itself is interactive or not. By learning the pattern a known 667 server produces, a user can easily find out that the host key has changed 668 when a completely different pattern is displayed. Because these patterns 669 are not unambiguous however, a pattern that looks similar to the pattern 670 remembered only gives a good probability that the host key is the same, 671 not guaranteed proof. 672 673 To get a listing of the fingerprints along with their random art for all 674 known hosts, the following command line can be used: 675 676 $ ssh-keygen -lv -f ~/.ssh/known_hosts 677 678 If the fingerprint is unknown, an alternative method of verification is 679 available: SSH fingerprints verified by DNS. An additional resource 680 record (RR), SSHFP, is added to a zonefile and the connecting client is 681 able to match the fingerprint with that of the key presented. 682 683 In this example, we are connecting a client to a server, 684 M-bM-^@M-^\host.example.comM-bM-^@M-^]. The SSHFP resource records should first be added to 685 the zonefile for host.example.com: 686 687 $ ssh-keygen -r host.example.com. 688 689 The output lines will have to be added to the zonefile. To check that 690 the zone is answering fingerprint queries: 691 692 $ dig -t SSHFP host.example.com 693 694 Finally the client connects: 695 696 $ ssh -o "VerifyHostKeyDNS ask" host.example.com 697 [...] 698 Matching host key fingerprint found in DNS. 699 Are you sure you want to continue connecting (yes/no)? 700 701 See the VerifyHostKeyDNS option in ssh_config(5) for more information. 702 703 SSH-BASED VIRTUAL PRIVATE NETWORKS 704 ssh contains support for Virtual Private Network (VPN) tunnelling using 705 the tun(4) network pseudo-device, allowing two networks to be joined 706 securely. The sshd_config(5) configuration option PermitTunnel controls 707 whether the server supports this, and at what level (layer 2 or 3 708 traffic). 709 710 The following example would connect client network 10.0.50.0/24 with 711 remote network 10.0.99.0/24 using a point-to-point connection from 712 10.1.1.1 to 10.1.1.2, provided that the SSH server running on the gateway 713 to the remote network, at 192.168.1.15, allows it. 714 715 On the client: 716 717 # ssh -f -w 0:1 192.168.1.15 true 718 # ifconfig tun0 10.1.1.1 10.1.1.2 netmask 255.255.255.252 719 # route add 10.0.99.0/24 10.1.1.2 720 721 On the server: 722 723 # ifconfig tun1 10.1.1.2 10.1.1.1 netmask 255.255.255.252 724 # route add 10.0.50.0/24 10.1.1.1 725 726 Client access may be more finely tuned via the /root/.ssh/authorized_keys 727 file (see below) and the PermitRootLogin server option. The following 728 entry would permit connections on tun(4) device 1 from user M-bM-^@M-^\janeM-bM-^@M-^] and on 729 tun device 2 from user M-bM-^@M-^\johnM-bM-^@M-^], if PermitRootLogin is set to 730 M-bM-^@M-^\forced-commands-onlyM-bM-^@M-^]: 731 732 tunnel="1",command="sh /etc/netstart tun1" ssh-rsa ... jane 733 tunnel="2",command="sh /etc/netstart tun2" ssh-rsa ... john 734 735 Since an SSH-based setup entails a fair amount of overhead, it may be 736 more suited to temporary setups, such as for wireless VPNs. More 737 permanent VPNs are better provided by tools such as ipsecctl(8) and 738 isakmpd(8). 739 740 ENVIRONMENT 741 ssh will normally set the following environment variables: 742 743 DISPLAY The DISPLAY variable indicates the location of the 744 X11 server. It is automatically set by ssh to 745 point to a value of the form M-bM-^@M-^\hostname:nM-bM-^@M-^], where 746 M-bM-^@M-^\hostnameM-bM-^@M-^] indicates the host where the shell runs, 747 and M-bM-^@M-^XnM-bM-^@M-^Y is an integer M-bM-^IM-% 1. ssh uses this special 748 value to forward X11 connections over the secure 749 channel. The user should normally not set DISPLAY 750 explicitly, as that will render the X11 connection 751 insecure (and will require the user to manually 752 copy any required authorization cookies). 753 754 HOME Set to the path of the user's home directory. 755 756 LOGNAME Synonym for USER; set for compatibility with 757 systems that use this variable. 758 759 MAIL Set to the path of the user's mailbox. 760 761 PATH Set to the default PATH, as specified when 762 compiling ssh. 763 764 SSH_ASKPASS If ssh needs a passphrase, it will read the 765 passphrase from the current terminal if it was run 766 from a terminal. If ssh does not have a terminal 767 associated with it but DISPLAY and SSH_ASKPASS are 768 set, it will execute the program specified by 769 SSH_ASKPASS and open an X11 window to read the 770 passphrase. This is particularly useful when 771 calling ssh from a .xsession or related script. 772 (Note that on some machines it may be necessary to 773 redirect the input from /dev/null to make this 774 work.) 775 776 SSH_AUTH_SOCK Identifies the path of a UNIX-domain socket used to 777 communicate with the agent. 778 779 SSH_CONNECTION Identifies the client and server ends of the 780 connection. The variable contains four space- 781 separated values: client IP address, client port 782 number, server IP address, and server port number. 783 784 SSH_ORIGINAL_COMMAND This variable contains the original command line if 785 a forced command is executed. It can be used to 786 extract the original arguments. 787 788 SSH_TTY This is set to the name of the tty (path to the 789 device) associated with the current shell or 790 command. If the current session has no tty, this 791 variable is not set. 792 793 TZ This variable is set to indicate the present time 794 zone if it was set when the daemon was started 795 (i.e. the daemon passes the value on to new 796 connections). 797 798 USER Set to the name of the user logging in. 799 800 Additionally, ssh reads ~/.ssh/environment, and adds lines of the format 801 M-bM-^@M-^\VARNAME=valueM-bM-^@M-^] to the environment if the file exists and users are 802 allowed to change their environment. For more information, see the 803 PermitUserEnvironment option in sshd_config(5). 804 805 FILES 806 ~/.rhosts 807 This file is used for host-based authentication (see above). On 808 some machines this file may need to be world-readable if the 809 user's home directory is on an NFS partition, because sshd(8) 810 reads it as root. Additionally, this file must be owned by the 811 user, and must not have write permissions for anyone else. The 812 recommended permission for most machines is read/write for the 813 user, and not accessible by others. 814 815 ~/.shosts 816 This file is used in exactly the same way as .rhosts, but allows 817 host-based authentication without permitting login with 818 rlogin/rsh. 819 820 ~/.ssh/ 821 This directory is the default location for all user-specific 822 configuration and authentication information. There is no 823 general requirement to keep the entire contents of this directory 824 secret, but the recommended permissions are read/write/execute 825 for the user, and not accessible by others. 826 827 ~/.ssh/authorized_keys 828 Lists the public keys (DSA, ECDSA, Ed25519, RSA) that can be used 829 for logging in as this user. The format of this file is 830 described in the sshd(8) manual page. This file is not highly 831 sensitive, but the recommended permissions are read/write for the 832 user, and not accessible by others. 833 834 ~/.ssh/config 835 This is the per-user configuration file. The file format and 836 configuration options are described in ssh_config(5). Because of 837 the potential for abuse, this file must have strict permissions: 838 read/write for the user, and not writable by others. 839 840 ~/.ssh/environment 841 Contains additional definitions for environment variables; see 842 ENVIRONMENT, above. 843 844 ~/.ssh/identity 845 ~/.ssh/id_dsa 846 ~/.ssh/id_ecdsa 847 ~/.ssh/id_ed25519 848 ~/.ssh/id_rsa 849 Contains the private key for authentication. These files contain 850 sensitive data and should be readable by the user but not 851 accessible by others (read/write/execute). ssh will simply 852 ignore a private key file if it is accessible by others. It is 853 possible to specify a passphrase when generating the key which 854 will be used to encrypt the sensitive part of this file using 855 3DES. 856 857 ~/.ssh/identity.pub 858 ~/.ssh/id_dsa.pub 859 ~/.ssh/id_ecdsa.pub 860 ~/.ssh/id_ed25519.pub 861 ~/.ssh/id_rsa.pub 862 Contains the public key for authentication. These files are not 863 sensitive and can (but need not) be readable by anyone. 864 865 ~/.ssh/known_hosts 866 Contains a list of host keys for all hosts the user has logged 867 into that are not already in the systemwide list of known host 868 keys. See sshd(8) for further details of the format of this 869 file. 870 871 ~/.ssh/rc 872 Commands in this file are executed by ssh when the user logs in, 873 just before the user's shell (or command) is started. See the 874 sshd(8) manual page for more information. 875 876 /etc/hosts.equiv 877 This file is for host-based authentication (see above). It 878 should only be writable by root. 879 880 /etc/shosts.equiv 881 This file is used in exactly the same way as hosts.equiv, but 882 allows host-based authentication without permitting login with 883 rlogin/rsh. 884 885 /etc/ssh/ssh_config 886 Systemwide configuration file. The file format and configuration 887 options are described in ssh_config(5). 888 889 /etc/ssh/ssh_host_key 890 /etc/ssh/ssh_host_dsa_key 891 /etc/ssh/ssh_host_ecdsa_key 892 /etc/ssh/ssh_host_ed25519_key 893 /etc/ssh/ssh_host_rsa_key 894 These files contain the private parts of the host keys and are 895 used for host-based authentication. If protocol version 1 is 896 used, ssh must be setuid root, since the host key is readable 897 only by root. For protocol version 2, ssh uses ssh-keysign(8) to 898 access the host keys, eliminating the requirement that ssh be 899 setuid root when host-based authentication is used. By default 900 ssh is not setuid root. 901 902 /etc/ssh/ssh_known_hosts 903 Systemwide list of known host keys. This file should be prepared 904 by the system administrator to contain the public host keys of 905 all machines in the organization. It should be world-readable. 906 See sshd(8) for further details of the format of this file. 907 908 /etc/ssh/sshrc 909 Commands in this file are executed by ssh when the user logs in, 910 just before the user's shell (or command) is started. See the 911 sshd(8) manual page for more information. 912 913 EXIT STATUS 914 ssh exits with the exit status of the remote command or with 255 if an 915 error occurred. 916 917 SEE ALSO 918 scp(1), sftp(1), ssh-add(1), ssh-agent(1), ssh-keygen(1), ssh-keyscan(1), 919 tun(4), ssh_config(5), ssh-keysign(8), sshd(8) 920 921 STANDARDS 922 S. Lehtinen and C. Lonvick, The Secure Shell (SSH) Protocol Assigned 923 Numbers, RFC 4250, January 2006. 924 925 T. Ylonen and C. Lonvick, The Secure Shell (SSH) Protocol Architecture, 926 RFC 4251, January 2006. 927 928 T. Ylonen and C. Lonvick, The Secure Shell (SSH) Authentication Protocol, 929 RFC 4252, January 2006. 930 931 T. Ylonen and C. Lonvick, The Secure Shell (SSH) Transport Layer 932 Protocol, RFC 4253, January 2006. 933 934 T. Ylonen and C. Lonvick, The Secure Shell (SSH) Connection Protocol, RFC 935 4254, January 2006. 936 937 J. Schlyter and W. Griffin, Using DNS to Securely Publish Secure Shell 938 (SSH) Key Fingerprints, RFC 4255, January 2006. 939 940 F. Cusack and M. Forssen, Generic Message Exchange Authentication for the 941 Secure Shell Protocol (SSH), RFC 4256, January 2006. 942 943 J. Galbraith and P. Remaker, The Secure Shell (SSH) Session Channel Break 944 Extension, RFC 4335, January 2006. 945 946 M. Bellare, T. Kohno, and C. Namprempre, The Secure Shell (SSH) Transport 947 Layer Encryption Modes, RFC 4344, January 2006. 948 949 B. Harris, Improved Arcfour Modes for the Secure Shell (SSH) Transport 950 Layer Protocol, RFC 4345, January 2006. 951 952 M. Friedl, N. Provos, and W. Simpson, Diffie-Hellman Group Exchange for 953 the Secure Shell (SSH) Transport Layer Protocol, RFC 4419, March 2006. 954 955 J. Galbraith and R. Thayer, The Secure Shell (SSH) Public Key File 956 Format, RFC 4716, November 2006. 957 958 D. Stebila and J. Green, Elliptic Curve Algorithm Integration in the 959 Secure Shell Transport Layer, RFC 5656, December 2009. 960 961 A. Perrig and D. Song, Hash Visualization: a New Technique to improve 962 Real-World Security, 1999, International Workshop on Cryptographic 963 Techniques and E-Commerce (CrypTEC '99). 964 965 AUTHORS 966 OpenSSH is a derivative of the original and free ssh 1.2.12 release by 967 Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo 968 de Raadt and Dug Song removed many bugs, re-added newer features and 969 created OpenSSH. Markus Friedl contributed the support for SSH protocol 970 versions 1.5 and 2.0. 971 972 OpenBSD 5.8 July 20, 2015 OpenBSD 5.8 973