TOOL » LINUX » SSH

Ssh

Usage

shell
ssh OPTIONS HOST COMMAND
OptionDescription
-iSpecify an identity file.
-tOpen a tty even if there are COMMANDs.
-X -YEnable trusted X11 forwarding.
-oAllow specifying options in the configuration file format.
-fGo to background just before command execution.
-NDo not execute a remote command. This is useful for just forwarding ports.
-TDisable pseudo-terminal allocation.
-MPlaces the ssh client into "master" mode for connection sharing.
-SSpecifies the location of a control socket for connection sharing.
Config OptionValuesDescription
StrictHostKeyCheckingyes/accept-new/no/askVerify host fingerprint.

X11 forwarding

Step servers does not need any packages to be installed. The destination server needs a X11 package, as follows:

DistroPackage
Ubuntu 20.04dbus-x11
CentOS 8xorg-x11-xauth

Port forward

When forwarding ports, keep in mind that a tunnel is created between the local (current) machine and the remote machine.

Local port forwarding

Forward requests from local:123 to A:456. (local:123A:456)

shell
ssh -L 123:localhost:456 A

Remote port forwarding

Forward requests from B:456 to local:123. (local:123B:456)

shell
ssh -R 456:localhost:123 B

Dynamic forwarding

Creates a SOCKS server that will forward connections through it. Use as a proxy server.

shell
ssh -D 1080 A

Terminal

When SSH'ing a server, the environment variable TERM will be inherited by default. To change it instead, use:

shell
env TERM=xterm ssh

The environment variable COLORTERM may be needed for programs that use truecolor, but it is not inherited by the destination server. Before running the program remotely or in the remote shell's rc file, define it.

fish
set -gx COLORTERM truecolor

Example

Port-forward a SSH connection in the background:

shell
ssh -fNTMS my-socket -D 1070 HOST
ssh -S my-socket -O check HOST
ssh -S my-socket -O exit HOST

Run an interactive command remotely:

shell
ssh -t HOST interactive_command arg1 arg2 ...