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