TOOL » LINUX » SSH

Ssh

Usage

shell
ssh OPTIONS host COMMAND
OptionDescription
-iSpecify an identity file.
-tOpen a tty even with 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

Example

Port-forward a SSH connection in the background:

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