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