Ssh
Usage
ssh OPTIONS HOST COMMAND| Option | Description |
|---|---|
-i | Specify an identity file. |
-t | Open a tty even if there are COMMANDs. |
-X -Y | Enable trusted X11 forwarding. |
-o | Allow specifying options in the configuration file format. |
-f | Go to background just before command execution. |
-N | Do not execute a remote command. This is useful for just forwarding ports. |
-T | Disable pseudo-terminal allocation. |
-M | Places the ssh client into "master" mode for connection sharing. |
-S | Specifies the location of a control socket for connection sharing. |
-C | Enable compression of all data being transfered. |
| Config Option | Values | Description |
|---|---|---|
StrictHostKeyChecking | yes/accept-new/no/ask | Verify host fingerprint. |
X11 forwarding
Step servers does not need any packages to be installed. The destination server needs a X11 package, as follows:
| Distro | Package |
|---|---|
| Ubuntu 20.04 | dbus-x11 |
| CentOS 8 | xorg-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:123 → A:456)
ssh -L 123:localhost:456 ARemote port forwarding
Forward requests from B:456 to local:123. (local:123 ← B:456)
ssh -R 456:localhost:123 BDynamic forwarding
Creates a SOCKS server that will forward connections through it. Use as a proxy server.
ssh -D 1080 ATerminal
When SSH'ing a server, the environment variable TERM will be inherited by default. To change it instead, use:
env TERM=xterm sshThe 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.
set -gx COLORTERM truecolorExample
Port-forward a SSH connection in the background:
ssh -fNTMS my-socket -D 1070 HOST
ssh -S my-socket -O check HOST
ssh -S my-socket -O exit HOSTRun an interactive command remotely:
ssh -t HOST interactive_command arg1 arg2 ...