Linux "rsh" Command Line Options and Examples
OpenSSH SSH client

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.


Usage:

ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file]
[-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-J [user@]host[:port]] [-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]] [user@]hostname [command]






Command Line Options:

-4
Forces ssh to use IPv4 addresses only.
rsh -4 ...
-6
Forces ssh to use IPv6 addresses only.
rsh -6 ...
-a
Disables forwarding of the authentication agent connection.
rsh -a ...
-b
Use bind_address on the local machine as the source address of the connection. Only useful on systemswith more than one address.
rsh -b ...
-c
Selects the cipher specification for encrypting the session. cipher_spec is a comma-separated list ofciphers listed in order of preference. See the Ciphers keyword in ssh_config(5) for more information.
rsh -c ...
-D
Specifies a local “dynamic” application-level port forwarding. This works by allocating a socket tolisten to port on the local side, optionally bound to the specified bind_address. Whenever a connectionis made to this port, the connection is forwarded over the secure channel, and the application protocolis then used to determine where to connect to from the remote machine. Currently the SOCKS4 and SOCKS5protocols are supported, and ssh will act as a SOCKS server. Only root can forward privileged ports.Dynamic port forwardings can also be specified in the configuration file.IPv6 addresses can be specified by enclosing the address in square brackets. Only the superuser canforward privileged ports. By default, the local port is bound in accordance with the GatewayPorts set‐ting. However, an explicit bind_address may be used to bind the connection to a specific address. Thebind_address of “localhost” indicates that the listening port be bound for local use only, while anempty address or ‘*’ indicates that the port should be available from all interfaces.
rsh -D ...
-E
Append debug logs to log_file instead of standard error.
rsh -E ...
-e
Sets the escape character for sessions with a pty (default: ‘~’). The escape character is only recog‐nized 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.
rsh -e ...
-F
Specifies an alternative per-user configuration file. If a configuration file is given on the commandline, the system-wide configuration file (/etc/ssh/ssh_config) will be ignored. The default for theper-user configuration file is ~/.ssh/config.
rsh -F ...
-G
Causes ssh to print its configuration after evaluating Host and Match blocks and exit.
rsh -G ...
-I
Specify the PKCS#11 shared library ssh should use to communicate with a PKCS#11 token providing theuser's private RSA key.
rsh -I ...
-i
Selects a file from which the identity (private key) for public key authentication is read. The defaultis ~/.ssh/id_dsa, ~/.ssh/id_ecdsa, ~/.ssh/id_ed25519 and ~/.ssh/id_rsa. Identity files may also bespecified 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 explicitlyspecified by the CertificateFile directive, ssh will also try to load certificate information from thefilename obtained by appending -cert.pub to identity filenames.
rsh -i ...
-J
Connect to the target host by first making a ssh connection to the jump host and then establishing a TCPforwarding to the ultimate destination from there. Multiple jump hops may be specified separated bycomma characters. This is a shortcut to specify a ProxyJump configuration directive.
rsh -J ...
-K
Enables GSSAPI-based authentication and forwarding (delegation) of GSSAPI credentials to the server.
rsh -K ...
-k
Disables forwarding (delegation) of GSSAPI credentials to the server.
rsh -k ...
-L
[bind_address:]port:host:hostport
rsh -L ...
-l
Specifies the user to log in as on the remote machine. This also may be specified on a per-host basisin the configuration file.
rsh -l ...
-m
A comma-separated list of MAC (message authentication code) algorithms, specified in order of prefer‐ence. See the MACs keyword for more information.
rsh -m ...
-N
Do not execute a remote command. This is useful for just forwarding ports.
rsh -N ...
-O
Control an active connection multiplexing master process. When the -O option is specified, the ctl_cmdargument is interpreted and passed to the master process. Valid commands are: “check” (check that themaster process is running), “forward” (request forwardings without command execution), “cancel” (cancelforwardings), “exit” (request the master to exit), and “stop” (request the master to stop accepting fur‐ther multiplexing requests).
rsh -O ...
-o
Can be used to give options in the format used in the configuration file. This is useful for specifyingoptions for which there is no separate command-line flag. For full details of the options listed below,and their possible values, see ssh_config(5).AddKeysToAgentAddressFamilyBatchModeBindAddressCanonicalDomainsCanonicalizeFallbackLocalCanonicalizeHostnameCanonicalizeMaxDotsCanonicalizePermittedCNAMEsCertificateFileChallengeResponseAuthenticationCheckHostIPCiphersClearAllForwardingsCompressionConnectionAttemptsConnectTimeoutControlMasterControlPathControlPersistDynamicForwardEscapeCharExitOnForwardFailureFingerprintHashForwardAgentForwardX11ForwardX11TimeoutForwardX11TrustedGatewayPortsGlobalKnownHostsFileGSSAPIAuthenticationGSSAPIDelegateCredentialsHashKnownHostsHostHostbasedAuthenticationHostbasedKeyTypesHostKeyAlgorithmsHostKeyAliasHostNameIdentitiesOnlyIdentityAgentIdentityFileIncludeIPQoSKbdInteractiveAuthenticationKbdInteractiveDevicesKexAlgorithmsLocalCommandLocalForwardLogLevelMACsMatchNoHostAuthenticationForLocalhostNumberOfPasswordPromptsPasswordAuthenticationPermitLocalCommandPKCS11ProviderPortPreferredAuthenticationsProxyCommandProxyJumpProxyUseFdpassPubkeyAcceptedKeyTypesPubkeyAuthenticationRekeyLimitRemoteCommandRemoteForwardRequestTTYSendEnvServerAliveIntervalServerAliveCountMaxStreamLocalBindMaskStreamLocalBindUnlinkStrictHostKeyCheckingTCPKeepAliveTunnelTunnelDeviceUpdateHostKeysUsePrivilegedPortUserUserKnownHostsFileVerifyHostKeyDNSVisualHostKeyXAuthLocation
rsh -o ...
-p
Port to connect to on the remote host. This can be specified on a per-host basis in the configurationfile.
rsh -p ...
-Q
Queries ssh for the algorithms supported for the specified version 2. The available features are:cipher (supported symmetric ciphers), cipher-auth (supported symmetric ciphers that support authenti‐cated encryption), mac (supported message integrity codes), kex (key exchange algorithms), key (keytypes), key-cert (certificate key types), key-plain (non-certificate key types), and protocol-version(supported SSH protocol versions).
rsh -Q ...
-q
Quiet mode. Causes most warning and diagnostic messages to be suppressed.
rsh -q ...
-R
[bind_address:]port:host:hostport
rsh -R ...
-S
Specifies the location of a control socket for connection sharing, or the string “none” to disable con‐nection sharing. Refer to the description of ControlPath and ControlMaster in ssh_config(5) fordetails.
rsh -S ...
-T
Disable pseudo-terminal allocation.
rsh -T ...
-V
Display the version number and exit.
rsh -V ...
-W
Requests that standard input and output on the client be forwarded to host on port over the secure chan‐nel. Implies -N, -T, ExitOnForwardFailure and ClearAllForwardings, though these can be overridden inthe configuration file or using -o command line options.
rsh -W ...
-w
Requests tunnel device forwarding with the specified tun(4) devices between the client (local_tun) andthe server (remote_tun).The devices may be specified by numerical ID or the keyword “any”, which uses the next available tunneldevice. If remote_tun is not specified, it defaults to “any”. See also the Tunnel and TunnelDevicedirectives in ssh_config(5). If the Tunnel directive is unset, it is set to the default tunnel mode,which is “point-to-point”.
rsh -w ...
-x
Disables X11 forwarding.
rsh -x ...
-KL[bind_address:]port
dynamic port-forwardings. !command allows the user to execute a local command if the PermitLocalCommandoption is enabled in ssh_config(5). Basic help is available, using the -h option.~R Request rekeying of the connection (only useful if the peer supports it).~V Decrease the verbosity (LogLevel) when errors are being written to stderr.~v Increase the verbosity (LogLevel) when errors are being written to stderr.TCP FORWARDINGForwarding of arbitrary TCP connections over the secure channel can be specified either on the command line orin a configuration file. One possible application of TCP forwarding is a secure connection to a mail server;another is going through firewalls.In the example below, we look at encrypting communication between an IRC client and server, even though the IRCserver does not directly support encrypted communications. This works as follows: the user connects to theremote host using ssh, specifying a port to be used to forward connections to the remote server. After that itis possible to start the service which is to be encrypted on the client machine, connecting to the same localport, and ssh will encrypt and forward the connection.The following example tunnels an IRC session from client machine “127.0.0.1” (localhost) to remote server“server.example.com”:$ ssh -f -L 1234:localhost:6667 server.example.com sleep 10$ irc -c '#users' -p 1234 pinky 127.0.0.1This tunnels a connection to IRC server “server.example.com”, joining channel “#users”, nickname “pinky”, usingport 1234. It doesn't matter which port is used, as long as it's greater than 1023 (remember, only root canopen sockets on privileged ports) and doesn't conflict with any ports already in use. The connection is for‐warded to port 6667 on the remote server, since that's the standard port for IRC services.The -f option backgrounds ssh and the remote command “sleep 10” is specified to allow an amount of time (10 sec‐onds, in the example) to start the service which is to be tunnelled. If no connections are made within the timespecified, ssh will exit.X11 FORWARDINGIf the ForwardX11 variable is set to “yes” (or see the description of the -X, -x, and -Y options above) and theuser is using X11 (the DISPLAY environment variable is set), the connection to the X11 display is automaticallyforwarded to the remote side in such a way that any X11 programs started from the shell (or command) will gothrough the encrypted channel, and the connection to the real X server will be made from the local machine. Theuser should not manually set DISPLAY. Forwarding of X11 connections can be configured on the command line or inconfiguration 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 con‐nections over the encrypted channel.ssh will also automatically set up Xauthority data on the server machine. For this purpose, it will generate arandom authorization cookie, store it in Xauthority on the server, and verify that any forwarded connectionscarry this cookie and replace it by the real cookie when the connection is opened. The real authenticationcookie is never sent to the server machine (and no cookies are sent in the plain).If the ForwardAgent variable is set to “yes” (or see the description of the -A and -a options above) and theuser is using an authentication agent, the connection to the agent is automatically forwarded to the remoteside.VERIFYING HOST KEYSWhen connecting to a server for the first time, a fingerprint of the server's public key is presented to theuser (unless the option StrictHostKeyChecking has been disabled). Fingerprints can be determined usingssh-keygen(1):$ ssh-keygen -l -f /etc/ssh/ssh_host_rsa_keyIf 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 fin‐gerprint algorithm to match.Because of the difficulty of comparing host keys just by looking at fingerprint strings, there is also supportto compare host keys visually, using random art. By setting the VisualHostKey option to “yes”, a small ASCIIgraphic gets displayed on every login to a server, no matter if the session itself is interactive or not. Bylearning the pattern a known server produces, a user can easily find out that the host key has changed when acompletely different pattern is displayed. Because these patterns are not unambiguous however, a pattern thatlooks similar to the pattern remembered only gives a good probability that the host key is the same, not guaran‐teed proof.To get a listing of the fingerprints along with their random art for all known hosts, the following command linecan be used:$ ssh-keygen -lv -f ~/.ssh/known_hostsIf the fingerprint is unknown, an alternative method of verification is available: SSH fingerprints verified byDNS. An additional resource record (RR), SSHFP, is added to a zonefile and the connecting client is able tomatch the fingerprint with that of the key presented.In this example, we are connecting a client to a server, “host.example.com”. The SSHFP resource records shouldfirst be added to the zonefile for host.example.com:$ ssh-keygen -r host.example.com.The output lines will have to be added to the zonefile. To check that the zone is answering fingerprintqueries:$ dig -t SSHFP host.example.comFinally the client connects:$ ssh -o "VerifyHostKeyDNS ask" host.example.com[...]Matching host key fingerprint found in DNS.Are you sure you want to continue connecting (yes/no)?See the VerifyHostKeyDNS option in ssh_config(5) for more information.SSH-BASED VIRTUAL PRIVATE NETWORKSssh contains support for Virtual Private Network (VPN) tunnelling using the tun(4) network pseudo-device, allow‐ing two networks to be joined securely. The sshd_config(5) configuration option PermitTunnel controls whetherthe server supports this, and at what level (layer 2 or 3 traffic).The following example would connect client network 10.0.50.0/24 with remote 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 remotenetwork, at 192.168.1.15, allows it.On the client:# ssh -f -w 0:1 192.168.1.15 true# ifconfig tun0 10.1.1.1 10.1.1.2 netmask 255.255.255.252# route add 10.0.99.0/24 10.1.1.2On the server:# ifconfig tun1 10.1.1.2 10.1.1.1 netmask 255.255.255.252# route add 10.0.50.0/24 10.1.1.1Client access may be more finely tuned via the /root/.ssh/authorized_keys file (see below) and thePermitRootLogin server option. The following entry would permit connections on tun(4) device 1 from user “jane”and on tun device 2 from user “john”, if PermitRootLogin is set to “forced-commands-only”:tunnel="1",command="sh /etc/netstart tun1" ssh-rsa ... janetunnel="2",command="sh /etc/netstart tun2" ssh-rsa ... johnSince an SSH-based setup entails a fair amount of overhead, it may be more suited to temporary setups, such asfor wireless VPNs. More permanent VPNs are better provided by tools such as ipsecctl(8) and isakmpd(8).ENVIRONMENTssh will normally set the following environment variables:DISPLAY The DISPLAY variable indicates the location of the X11 server. It is automatically set byssh to point to a value of the form “hostname:n”, where “hostname” indicates the hostwhere the shell runs, and ‘n’ is an integer ≥ 1. ssh uses this special value to forwardX11 connections over the secure channel. The user should normally not set DISPLAY explic‐itly, as that will render the X11 connection insecure (and will require the user to manu‐ally copy any required authorization cookies).HOME Set to the path of the user's home directory.LOGNAME Synonym for USER; set for compatibility with systems that use this variable.MAIL Set to the path of the user's mailbox.PATH Set to the default PATH, as specified when compiling ssh.SSH_ASKPASS If ssh needs a passphrase, it will read the passphrase from the current terminal if it wasrun from a terminal. If ssh does not have a terminal associated with it but DISPLAY andSSH_ASKPASS are set, it will execute the program specified by SSH_ASKPASS and open an X11window to read the passphrase. This is particularly useful when calling ssh from a.xsession or related script. (Note that on some machines it may be necessary to redirectthe input from /dev/null to make this work.)SSH_AUTH_SOCK Identifies the path of a UNIX-domain socket used to communicate with the agent.SSH_CONNECTION Identifies the client and server ends of the connection. The variable contains fourspace-separated values: client IP address, client port number, server IP address, andserver port number.SSH_ORIGINAL_COMMAND This variable contains the original command line if a forced command is executed. It canbe used to extract the original arguments.SSH_TTY This is set to the name of the tty (path to the device) associated with the current shellor command. If the current session has no tty, this variable is not set.TZ This variable is set to indicate the present time zone if it was set when the daemon wasstarted (i.e. the daemon passes the value on to new connections).USER Set to the name of the user logging in.Additionally, ssh reads ~/.ssh/environment, and adds lines of the format “VARNAME=value” to the environment ifthe file exists and users are allowed to change their environment. For more information, see thePermitUserEnvironment option in sshd_config(5).FILES~/.rhostsThis file is used for host-based authentication (see above). On some machines this file may need to beworld-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.~/.shostsThis file is used in exactly the same way as .rhosts, but allows host-based authentication without per‐mitting login with rlogin/rsh.~/.ssh/This directory is the default location for all user-specific configuration and authentication informa‐tion. There is no general requirement to keep the entire contents of this directory secret, but therecommended permissions are read/write/execute for the user, and not accessible by others.~/.ssh/authorized_keysLists the public keys (DSA, ECDSA, Ed25519, RSA) that can be used for logging in as this user. The for‐mat of this file is described in the sshd(8) manual page. This file is not highly sensitive, but therecommended permissions are read/write for the user, and not accessible by others.~/.ssh/configThis is the per-user configuration file. The file format and configuration options are described inssh_config(5). Because of the potential for abuse, this file must have strict permissions: read/writefor the user, and not writable by others. It may be group-writable provided that the group in questioncontains only the user.~/.ssh/environmentContains additional definitions for environment variables; see ENVIRONMENT, above.~/.ssh/id_dsa~/.ssh/id_ecdsa~/.ssh/id_ed25519~/.ssh/id_rsaContains the private key for authentication. These files contain sensitive data and should be readableby the user but not accessible by others (read/write/execute). ssh will simply ignore a private keyfile if it is accessible by others. It is possible to specify a passphrase when generating the keywhich will be used to encrypt the sensitive part of this file using 3DES.~/.ssh/id_dsa.pub~/.ssh/id_ecdsa.pub~/.ssh/id_ed25519.pub~/.ssh/id_rsa.pubContains the public key for authentication. These files are not sensitive and can (but need not) bereadable by anyone.~/.ssh/known_hostsContains a list of host keys for all hosts the user has logged into that are not already in the sys‐temwide list of known host keys. See sshd(8) for further details of the format of this file.~/.ssh/rcCommands in this file are executed by ssh when the user logs in, just before the user's shell (or com‐mand) is started. See the sshd(8) manual page for more information./etc/hosts.equivThis file is for host-based authentication (see above). It should only be writable by root./etc/ssh/shosts.equivThis file is used in exactly the same way as hosts.equiv, but allows host-based authentication withoutpermitting login with rlogin/rsh./etc/ssh/ssh_configSystemwide configuration file. The file format and configuration options are described inssh_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_keyThese files contain the private parts of the host keys and are used for host-based authentication./etc/ssh/ssh_known_hostsSystemwide list of known host keys. This file should be prepared by the system administrator to containthe public host keys of all machines in the organization. It should be world-readable. See sshd(8) forfurther details of the format of this file./etc/ssh/sshrcCommands in this file are executed by ssh when the user logs in, just before the user's shell (or com‐mand) is started. See the sshd(8) manual page for more information.EXIT STATUSssh exits with the exit status of the remote command or with 255 if an error occurred.
rsh -KL[bind_address:]port ...