Secure, encrypted remote-shell and tunnelling utility
The ssh program from OpenSSH ≥ 9.x provides authenticated, encrypted, bidirectional byte streams between hosts. It replaces insecure protocols such as telnet, rlogin, and unencrypted rcp.
$ ssh [options] user@host [command …]
The ssh client also supports sophisticated
features such as agent forwarding, jump-host chaining, connection
multiplexing, dynamic port forwarding, and querying available
algorithms. All options below can be set on the CLI or in
~/.ssh/config
via Host blocks.
Controlling transport, login, and basic session behaviour
-p port
Connect to a non-default TCP port (default 22).
-l user
Login name (overrides user@host
syntax).
-i identity_file
Private-key(s) to use; repeatable for
alternative keys (ED25519, ECDSA, RSA, etc.).
-o Option=Value
Inline configuration override (any keyword from ssh_config(5)
).
-F path
Alternate ssh_config file.
-4
/ -6
Force IPv4 or IPv6.
-C
Enable zlib compression after authentication.
-q
Quiet mode — suppress most diagnostics.
Keys, passwords, agents, and multi-factor options
-A
Agent forwarding — delegate client keys to remote hops.
-a
Disable agent forwarding (opposite of -A
).
-K
GSSAPI authentication & credential forwarding.
-k
Disable GSSAPI credential forwarding.
-o PreferredAuthentications=…
Order methods (password, publickey, keyboard-interactive, etc.).
-E hash_alg
Select hash when hashing known_hosts with
-H (e.g. sha256
).
-J user@jump
One-shot ProxyJump; multiple hops comma-separated.
# Example — agent + jump host
$ ssh -A -J bastion.example.com user@10.42.0.5
Local, remote, and dynamic SOCKS tunnels
-L [bind:]lport:host:port
Local → remote; listens on lport.
-R [bind:]rport:host:port
Remote → local; server listens on rport.
-D [bind:]dport
Dynamic SOCKS v5 proxy (acts like a VPN).
-W host:port
TCP forward-only (drop interactive shell); complements -J
.
-N
Do not execute remote command (pure tunnelling).
-f
Background after authentication (requires -N
or
explicit command).
# Expose local PostgreSQL to office workstation
$ ssh -N -L 5432:localhost:5432 office@vpn.example.net
# SOCKS proxy on port 1080
$ ssh -f -N -D 1080 user@gateway
Reuse a single TCP connection for multiple sessions
Multiplexing dramatically speeds up scripted SSH workflows by avoiding repeated handshakes. Typical config block:
Host *
ControlMaster auto
ControlPath ~/.ssh/cm-%r@%h:%p
ControlPersist 2h
After the first session, subsequent ssh invocations to the same host instantly attach to the master socket.
Choosing ciphers, MACs, KEX, and querying capabilities
-Q cipher|mac|kex|key
List algorithms supported by current build.
-v
, -vvv
Diagnostic verbosity — shows algorithm negotiation.
-o Ciphers=…
,
-o MACs=…
,
-o KexAlgorithms=…
Override defaults; comma-separated preference list.
-o HostKeyAlgorithms=…
Advertise acceptable server key types (e.g. ssh-ed25519
).
# Audit supported MAC algorithms
$ ssh -Q mac
# Force FIPS-compliant suite
$ ssh -o Ciphers=aes256-gcm@openssh.com \
-o MACs=hmac-sha2-512-etm@openssh.com \
secure@example.gov
Environment, escapes, and pseudo-tty management
-t
/ -T
Force / disable allocation of pseudo-TTY.
-X
/ -Y
Untrusted / trusted X11 forwarding.
-x
Disable X11 forwarding in config that enables it.
-e char
Set escape character (default ~
); -e none
disables.
-V
Print version & compile-time options.
-G
Dump final config after all sources are processed then exit.
Debugging session health at the CLI
ssh returns the remote command’s exit code.
If no command is executed, it exits 0 on graceful logout,
255 on connection failure, or another
local-error code (SIGINT → 130
, etc.).
Interactive escapes (typed at column 1 after Enter
):
~.
Terminate connection immediately.~^Z
Suspend ssh and retain connection.~#
List forwarded ports.~&
Background session (like -fN
).Ready-to-use command lines for daily admin
$ ssh -o StrictHostKeyChecking=yes \
-o BatchMode=yes \
user@host 'tar czf - /var/log' | tar xzf -
$ ssh -i ~/.ssh/ci_ed25519 \
-o LogLevel=ERROR \
deploy@api 'jq -n --arg now "$(date -Is)" "{time:$now}"'
# On Raspberry Pi (behind router)
$ ssh -R 443:localhost:9443 \
-N -f -o ServerAliveInterval=30 \
pi@vps.example.net