SSH
SSH
NAME
ssh -- OpenSSH remote login client
SYNOPSIS
ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface] [-b bind_address]
[-c cipher_spec] [-D [bind_address:]port] [-E log_file]
[-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file]
[-J destination] [-L address] [-l login_name] [-m mac_spec]
[-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
[-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] destination
[command]
DESCRIPTION
ssh (SSH client) is a program for logging into a remote machine and for
executing commands on a remote machine. It is intended to provide secure
encrypted communications between two untrusted hosts over an insecure
network. X11 connections, arbitrary TCP ports and UNIX-domain sockets
can also be forwarded over the secure channel.
ssh connects and logs into the specified destination, which may be speci-
fied as either [user@]hostname or a URI of the form
ssh://[user@]hostname[:port]. The user must prove his/her identity to
the remote machine using one of several methods (see below).
-B bind_interface
Bind to the address of bind_interface before attempting to con-
nect to the destination host. This is only useful on systems
with more than one address.
-b bind_address
Use bind_address on the local machine as the source address of
the connection. Only useful on systems with more than one ad-
dress.
-C Requests compression of all data (including stdin, stdout,
stderr, and data for forwarded X11, TCP and UNIX-domain connec-
tions). The compression algorithm is the same used by gzip(1).
Compression is desirable on modem lines and other slow connec-
tions, but will only slow down things on fast networks. The de-
fault value can be set on a host-by-host basis in the configura-
tion files; see the Compression option.
-c cipher_spec
Selects the cipher specification for encrypting the session.
cipher_spec is a comma-separated list of ciphers listed in order
of preference. See the Ciphers keyword in ssh_config(5) for more
information.
-D [bind_address:]port
Specifies a local "dynamic" application-level port forwarding.
This works by allocating a socket to listen to port on the local
side, optionally bound to the specified bind_address. Whenever a
connection is made to this port, the connection is forwarded over
the secure channel, and the application protocol is then used to
determine where to connect to from the remote machine. Currently
the SOCKS4 and SOCKS5 protocols are supported, and ssh will act
as a SOCKS server. Only root can forward privileged ports. Dy-
namic port forwardings can also be specified in the configuration
file.
-E log_file
Append debug logs to log_file instead of standard error.
-e escape_char
Sets the escape character for sessions with a pty (default: '~').
The escape character is only recognized at the beginning of a
line. The escape character followed by a dot ('.') closes the
connection; followed by control-Z suspends the connection; and
followed by itself sends the escape character once. Setting the
character to "none" disables any escapes and makes the session
fully transparent.
-F configfile
Specifies an alternative per-user configuration file. If a con-
figuration file is given on the command line, the system-wide
configuration file (/etc/ssh/ssh_config) will be ignored. The
default for the per-user configuration file is ~/.ssh/config.
-I pkcs11
Specify the PKCS#11 shared library ssh should use to communicate
with a PKCS#11 token providing keys for user authentication.
-i identity_file
Selects a file from which the identity (private key) for public
key authentication is read. The default is ~/.ssh/id_dsa,
~/.ssh/id_ecdsa, ~/.ssh/id_ecdsa_sk, ~/.ssh/id_ed25519,
~/.ssh/id_ed25519_sk and ~/.ssh/id_rsa. Identity files may also
be specified on a per-host basis in the configuration file. It
is possible to have multiple -i options (and multiple identities
specified in configuration files). If no certificates have been
explicitly specified by the CertificateFile directive, ssh will
also try to load certificate information from the filename ob-
tained by appending -cert.pub to identity filenames.
-J destination
Connect to the target host by first making a ssh connection to
the jump host described by destination and then establishing a
TCP forwarding to the ultimate destination from there. Multiple
jump hops may be specified separated by comma characters. This
is a shortcut to specify a ProxyJump configuration directive.
Note that configuration directives supplied on the command-line
generally apply to the destination host and not any specified
jump hosts. Use ~/.ssh/config to specify configuration for jump
hosts.
-L [bind_address:]port:host:hostport
-L [bind_address:]port:remote_socket
-L local_socket:host:hostport
-L local_socket:remote_socket
Specifies that connections to the given TCP port or Unix socket
on the local (client) host are to be forwarded to the given host
and port, or Unix socket, on the remote side. This works by al-
locating a socket to listen to either a TCP port on the local
side, optionally bound to the specified bind_address, or to a
Unix socket. Whenever a connection is made to the local port or
socket, the connection is forwarded over the secure channel, and
a connection is made to either host port hostport, or the Unix
socket remote_socket, from the remote machine.
Port forwardings can also be specified in the configuration file.
Only the superuser can forward privileged ports. IPv6 addresses
can be specified by enclosing the address in square brackets.
-l login_name
Specifies the user to log in as on the remote machine. This also
may be specified on a per-host basis in the configuration file.
-M Places the ssh client into "master" mode for connection sharing.
Multiple -M options places ssh into "master" mode but with con-
firmation required using ssh-askpass(1) before each operation
that changes the multiplexing state (e.g. opening a new session).
Refer to the description of ControlMaster in ssh_config(5) for
details.
-m mac_spec
A comma-separated list of MAC (message authentication code) algo-
rithms, specified in order of preference. See the MACs keyword
for more information.
-O ctl_cmd
Control an active connection multiplexing master process. When
the -O option is specified, the ctl_cmd argument is interpreted
and passed to the master process. Valid commands are: "check"
(check that the master process is running), "forward" (request
forwardings without command execution), "cancel" (cancel forward-
ings), "exit" (request the master to exit), and "stop" (request
the master to stop accepting further multiplexing requests).
-o option
Can be used to give options in the format used in the configura-
tion file. This is useful for specifying options for which there
is no separate command-line flag. For full details of the op-
tions listed below, and their possible values, see ssh_config(5).
AddKeysToAgent
AddressFamily
BatchMode
BindAddress
CanonicalDomains
CanonicalizeFallbackLocal
CanonicalizeHostname
CanonicalizeMaxDots
CanonicalizePermittedCNAMEs
CASignatureAlgorithms
CertificateFile
ChallengeResponseAuthentication
CheckHostIP
Ciphers
ClearAllForwardings
Compression
ConnectionAttempts
ConnectTimeout
ControlMaster
ControlPath
ControlPersist
DynamicForward
EscapeChar
ExitOnForwardFailure
FingerprintHash
ForwardAgent
ForwardX11
ForwardX11Timeout
ForwardX11Trusted
GatewayPorts
GlobalKnownHostsFile
GSSAPIAuthentication
GSSAPIKeyExchange
GSSAPIClientIdentity
GSSAPIDelegateCredentials
GSSAPIKexAlgorithms
GSSAPIRenewalForcesRekey
GSSAPIServerIdentity
GSSAPITrustDns
HashKnownHosts
Host
HostbasedAuthentication
HostbasedKeyTypes
HostKeyAlgorithms
HostKeyAlias
Hostname
IdentitiesOnly
IdentityAgent
IdentityFile
IPQoS
KbdInteractiveAuthentication
KbdInteractiveDevices
KexAlgorithms
LocalCommand
LocalForward
LogLevel
MACs
Match
NoHostAuthenticationForLocalhost
NumberOfPasswordPrompts
PasswordAuthentication
PermitLocalCommand
PKCS11Provider
Port
PreferredAuthentications
ProxyCommand
ProxyJump
ProxyUseFdpass
PubkeyAcceptedKeyTypes
PubkeyAuthentication
RekeyLimit
RemoteCommand
RemoteForward
RequestTTY
SendEnv
ServerAliveInterval
ServerAliveCountMax
SetEnv
StreamLocalBindMask
StreamLocalBindUnlink
StrictHostKeyChecking
TCPKeepAlive
Tunnel
TunnelDevice
UpdateHostKeys
User
UserKnownHostsFile
VerifyHostKeyDNS
VisualHostKey
XAuthLocation
-p port
Port to connect to on the remote host. This can be specified on
a per-host basis in the configuration file.
-Q query_option
Queries ssh for the algorithms supported for the specified ver-
sion 2. The available features are: cipher (supported symmetric
ciphers), cipher-auth (supported symmetric ciphers that support
authenticated encryption), help (supported query terms for use
with the -Q flag), mac (supported message integrity codes), kex
(key exchange algorithms), kex-gss (GSSAPI key exchange algo-
rithms), key (key types), key-cert (certificate key types),
key-plain (non-certificate key types), key-sig (all key types and
signature algorithms), protocol-version (supported SSH protocol
versions), and sig (supported signature algorithms). Alterna-
tively, any keyword from ssh_config(5) or sshd_config(5) that
takes an algorithm list may be used as an alias for the corre-
sponding query_option.
-R [bind_address:]port:host:hostport
-R [bind_address:]port:local_socket
-R remote_socket:host:hostport
-R remote_socket:local_socket
-R [bind_address:]port
Specifies that connections to the given TCP port or Unix socket
on the remote (server) host are to be forwarded to the local
side.
This works by allocating a socket to listen to either a TCP port
or to a Unix socket on the remote side. Whenever a connection is
made to this port or Unix socket, the connection is forwarded
over the secure channel, and a connection is made from the local
machine to either an explicit destination specified by host port
hostport, or local_socket, or, if no explicit destination was
specified, ssh will act as a SOCKS 4/5 proxy and forward connec-
tions to the destinations requested by the remote SOCKS client.
-S ctl_path
Specifies the location of a control socket for connection shar-
ing, or the string "none" to disable connection sharing. Refer
to the description of ControlPath and ControlMaster in
ssh_config(5) for details.
-W host:port
Requests that standard input and output on the client be for-
warded to host on port over the secure channel. Implies -N, -T,
ExitOnForwardFailure and ClearAllForwardings, though these can be
overridden in the configuration file or using -o command line op-
tions.
-w local_tun[:remote_tun]
Requests tunnel device forwarding with the specified tun(4) de-
vices between the client (local_tun) and the server (remote_tun).
AUTHENTICATION
The OpenSSH SSH client supports SSH protocol 2.
The file ~/.ssh/authorized_keys lists the public keys that are permitted
for logging in. When the user logs in, the ssh program tells the server
which key pair it would like to use for authentication. The client
proves that it has access to the private key and the server checks that
the corresponding public key is authorized to accept the account.
The server may inform the client of errors that prevented public key au-
thentication from succeeding after authentication completes using a dif-
ferent method. These may be viewed by increasing the LogLevel to DEBUG
or higher (e.g. by using the -v flag).
The user creates his/her key pair by running ssh-keygen(1). This stores
the private key in ~/.ssh/id_dsa (DSA), ~/.ssh/id_ecdsa (ECDSA),
~/.ssh/id_ecdsa_sk (authenticator-hosted ECDSA), ~/.ssh/id_ed25519
(Ed25519), ~/.ssh/id_ed25519_sk (authenticator-hosted Ed25519), or
~/.ssh/id_rsa (RSA) and stores the public key in ~/.ssh/id_dsa.pub (DSA),
~/.ssh/id_ecdsa.pub (ECDSA), ~/.ssh/id_ecdsa_sk.pub (authenticator-hosted
ECDSA), ~/.ssh/id_ed25519.pub (Ed25519), ~/.ssh/id_ed25519_sk.pub (au-
thenticator-hosted Ed25519), or ~/.ssh/id_rsa.pub (RSA) in the user's
home directory. The user should then copy the public key to
~/.ssh/authorized_keys in his/her home directory on the remote machine.
The authorized_keys file corresponds to the conventional ~/.rhosts file,
and has one key per line, though the lines can be very long. After this,
the user can log in without giving the password.
Finally, if other authentication methods fail, ssh prompts the user for a
password. The password is sent to the remote host for checking; however,
since all communications are encrypted, the password cannot be seen by
someone listening on the network.
When the user's identity has been accepted by the server, the server ei-
ther executes the given command in a non-interactive session or, if no
command has been specified, logs into the machine and gives the user a
normal shell as an interactive session. All communication with the re-
mote command or shell will be automatically encrypted.
If a pseudo-terminal has been allocated the user may use the escape char-
acters noted below.
The session terminates when the command or shell on the remote machine
exits and all X11 and TCP connections have been closed.
ESCAPE CHARACTERS
When a pseudo-terminal has been requested, ssh supports a number of func-
tions through the use of an escape character.
~. Disconnect.
~^Z Background ssh.
~B Send a BREAK to the remote system (only useful if the peer sup-
ports it).
TCP FORWARDING
Forwarding of arbitrary TCP connections over a secure channel can be
specified either on the command line or in a configuration file. One
possible application of TCP forwarding is a secure connection to a mail
server; another is going through firewalls.
The following example tunnels an IRC session from the client to an IRC
server at "server.example.com", joining channel "#users", nickname
"pinky", using the standard IRC port, 6667:
The -f option backgrounds ssh and the remote command "sleep 10" is speci-
fied to allow an amount of time (10 seconds, in the example) to start the
program which is going to use the tunnel. If no connections are made
within the time specified, ssh will exit.
X11 FORWARDING
If the ForwardX11 variable is set to "yes" (or see the description of the
-X, -x, and -Y options above) and the user is using X11 (the DISPLAY en-
vironment variable is set), the connection to the X11 display is automat-
ically forwarded to the remote side in such a way that any X11 programs
started from the shell (or command) will go through the encrypted chan-
nel, and the connection to the real X server will be made from the local
machine. The user should not manually set DISPLAY. Forwarding of X11
connections can be configured on the command line or in configuration
files.
The DISPLAY value set by ssh will point to the server machine, but with a
display number greater than zero. This is normal, and happens because
ssh creates a "proxy" X server on the server machine for forwarding the
connections over the encrypted channel.
ssh will also automatically set up Xauthority data on the server machine.
For this purpose, it will generate a random authorization cookie, store
it in Xauthority on the server, and verify that any forwarded connections
carry this cookie and replace it by the real cookie when the connection
is opened. The real authentication cookie is never sent to the server
machine (and no cookies are sent in the plain).
$ ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key
If the fingerprint is already known, it can be matched and the key can be
accepted or rejected. If only legacy (MD5) fingerprints for the server
are available, the ssh-keygen(1) -E option may be used to downgrade the
fingerprint algorithm to match.
To get a listing of the fingerprints along with their random art for all
known hosts, the following command line can be used:
$ ssh-keygen -r host.example.com.
The output lines will have to be added to the zonefile. To check that
the zone is answering fingerprint queries:
The following example would connect client network 10.0.50.0/24 with re-
mote network 10.0.99.0/24 using a point-to-point connection from 10.1.1.1
to 10.1.1.2, provided that the SSH server running on the gateway to the
remote network, at 192.168.1.15, allows it.
On the client:
On the server:
ENVIRONMENT
ssh will normally set the following environment variables:
DISPLAY The DISPLAY variable indicates the location of the
X11 server. It is automatically set by ssh to
point to a value of the form "hostname:n", where
"hostname" indicates the host where the shell runs,
and 'n' is an integer >= 1. ssh uses this special
value to forward X11 connections over the secure
channel. The user should normally not set DISPLAY
explicitly, as that will render the X11 connection
insecure (and will require the user to manually
copy any required authorization cookies).
SSH_TTY This is set to the name of the tty (path to the de-
vice) associated with the current shell or command.
If the current session has no tty, this variable is
not set.
FILES
~/.rhosts
This file is used for host-based authentication (see above). On
some machines this file may need to be world-readable if the
user's home directory is on an NFS partition, because sshd(8)
reads it as root. Additionally, this file must be owned by the
user, and must not have write permissions for anyone else. The
recommended permission for most machines is read/write for the
user, and not accessible by others.
~/.shosts
This file is used in exactly the same way as .rhosts, but allows
host-based authentication without permitting login with
rlogin/rsh.
~/.ssh/
This directory is the default location for all user-specific con-
figuration and authentication information. There is no general
requirement to keep the entire contents of this directory secret,
but the recommended permissions are read/write/execute for the
user, and not accessible by others.
~/.ssh/authorized_keys
Lists the public keys (DSA, ECDSA, Ed25519, RSA) that can be used
for logging in as this user. The format of this file is de-
scribed in the sshd(8) manual page. This file is not highly sen-
sitive, but the recommended permissions are read/write for the
user, and not accessible by others.
~/.ssh/config
This is the per-user configuration file. The file format and
configuration options are described in ssh_config(5). Because of
the potential for abuse, this file must have strict permissions:
read/write for the user, and not writable by others. It may be
group-writable provided that the group in question contains only
the user.
~/.ssh/environment
Contains additional definitions for environment variables; see
ENVIRONMENT, above.
~/.ssh/id_dsa
~/.ssh/id_ecdsa
~/.ssh/id_ecdsa_sk
~/.ssh/id_ed25519
~/.ssh/id_ed25519_sk
~/.ssh/id_rsa
Contains the private key for authentication. These files contain
sensitive data and should be readable by the user but not acces-
sible by others (read/write/execute). ssh will simply ignore a
private key file if it is accessible by others. It is possible
to specify a passphrase when generating the key which will be
used to encrypt the sensitive part of this file using AES-128.
~/.ssh/id_dsa.pub
~/.ssh/id_ecdsa.pub
~/.ssh/id_ecdsa_sk.pub
~/.ssh/id_ed25519.pub
~/.ssh/id_ed25519_sk.pub
~/.ssh/id_rsa.pub
Contains the public key for authentication. These files are not
sensitive and can (but need not) be readable by anyone.
~/.ssh/known_hosts
Contains a list of host keys for all hosts the user has logged
into that are not already in the systemwide list of known host
keys. See sshd(8) for further details of the format of this
file.
~/.ssh/rc
Commands in this file are executed by ssh when the user logs in,
just before the user's shell (or command) is started. See the
sshd(8) manual page for more information.
/etc/hosts.equiv
This file is for host-based authentication (see above). It
should only be writable by root.
/etc/ssh/shosts.equiv
This file is used in exactly the same way as hosts.equiv, but al-
lows host-based authentication without permitting login with
rlogin/rsh.
/etc/ssh/ssh_config
Systemwide configuration file. The file format and configuration
options are described in ssh_config(5).
/etc/ssh/ssh_host_key
/etc/ssh/ssh_host_dsa_key
/etc/ssh/ssh_host_ecdsa_key
/etc/ssh/ssh_host_ed25519_key
/etc/ssh/ssh_host_rsa_key
These files contain the private parts of the host keys and are
used for host-based authentication.
/etc/ssh/ssh_known_hosts
Systemwide list of known host keys. This file should be prepared
by the system administrator to contain the public host keys of
all machines in the organization. It should be world-readable.
See sshd(8) for further details of the format of this file.
/etc/ssh/sshrc
Commands in this file are executed by ssh when the user logs in,
just before the user's shell (or command) is started. See the
sshd(8) manual page for more information.
EXIT STATUS
ssh exits with the exit status of the remote command or with 255 if an
error occurred.
SEE ALSO
scp(1), sftp(1), ssh-add(1), ssh-agent(1), ssh-argv0(1), ssh-keygen(1),
ssh-keyscan(1), tun(4), ssh_config(5), ssh-keysign(8), sshd(8)
STANDARDS
S. Lehtinen and C. Lonvick, The Secure Shell (SSH) Protocol Assigned
Numbers, RFC 4250, January 2006.
T. Ylonen and C. Lonvick, The Secure Shell (SSH) Connection Protocol, RFC
4254, January 2006.
J. Galbraith and P. Remaker, The Secure Shell (SSH) Session Channel Break
Extension, RFC 4335, January 2006.
B. Harris, Improved Arcfour Modes for the Secure Shell (SSH) Transport
Layer Protocol, RFC 4345, January 2006.
J. Galbraith and R. Thayer, The Secure Shell (SSH) Public Key File
Format, RFC 4716, November 2006.
AUTHORS
OpenSSH is a derivative of the original and free ssh 1.2.12 release by
Tatu Ylonen. Aaron Campbell, Bob Beck, Markus Friedl, Niels Provos, Theo
de Raadt and Dug Song removed many bugs, re-added newer features and cre-
ated OpenSSH. Markus Friedl contributed the support for SSH protocol
versions 1.5 and 2.0.
BSD February 7, 2020 BSD