ssh

Connect to a server, run commands and create encrypted tunnels.

Before you run

Confirm the host-key fingerprint through a trusted channel on first use. -N keeps only forwarding active; Ctrl+C stops these foreground tunnels. -L resolves its target from the SSH server; -R reaches its target from this computer. The remote listener still depends on server forwarding policy; loopback binding also depends on GatewayPorts. ExitOnForwardFailure checks initial forwarding setup, not every future destination. -D provides SOCKS, not a VPN: configure the client separately (including remote DNS when supported). Verbose logs can reveal addresses, usernames and key paths; redact before sharing.

Examples

Log in; expect a host-key check and authentication prompt.

ssh alice@server.example.com

Choose port 2222 and one identity file; IdentitiesOnly limits identities offered.

ssh -p 2222 -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes alice@server.example.com

Reach the destination through a bastion with ProxyJump (-J).

ssh -J alice@bastion.example.com alice@internal.example.com

Local forward: local port 15432 reaches the database through the server.

ssh -N -L 127.0.0.1:15432:db.internal.example.com:5432 -o ExitOnForwardFailure=yes alice@server.example.com

Remote forward: server loopback port 18080 reaches this computer’s port 8080.

ssh -N -R 127.0.0.1:18080:127.0.0.1:8080 -o ExitOnForwardFailure=yes alice@server.example.com

Create a local SOCKS listener on 127.0.0.1:1080.

ssh -N -D 127.0.0.1:1080 -o ExitOnForwardFailure=yes alice@server.example.com

Diagnose a connection with verbose output and a 10-second connection timeout.

ssh -vvv -o ConnectTimeout=10 alice@server.example.com

Connect through two jump hosts in order. The client authenticates to each hop; verify every host key.

ssh -J alice@jump1.example.com,alice@jump2.example.com alice@target.example.com

Print effective client settings after Host and Include matching. Output may contain private connection details.

ssh -G alice@server.example.com

Run one remote command and return to the local shell. Quote the command for the intended remote shell.

ssh alice@server.example.com 'uptime'

Create and reuse a connection, inspect it, then stop the master. Keep ~/.ssh private; stopping the master also closes its dependent sessions.

ssh -M -S ~/.ssh/securepipes-%C -o ControlPersist=10m -fN alice@server.example.com
ssh -S ~/.ssh/securepipes-%C alice@server.example.com
ssh -S ~/.ssh/securepipes-%C -O check alice@server.example.com
ssh -S ~/.ssh/securepipes-%C -O exit alice@server.example.com

List supported query categories, key algorithms and ciphers. Client support does not guarantee server acceptance.

ssh -Q help
ssh -Q key
ssh -Q cipher

Inspect a known_hosts entry and its fingerprint. Remove it only after independently verifying an expected key change; use the exact host and port form.

ssh-keygen -F server.example.com -l
ssh-keygen -R server.example.com

Use noninteractive mode and a connection timeout for scripts. Configure authentication and host-key trust beforehand; prompts cause failure.

ssh -o BatchMode=yes -o ConnectTimeout=10 alice@server.example.com

Use ProxyCommand with -W to reach a target through a bastion. ProxyJump is usually simpler; verify both host keys.

ssh -o 'ProxyCommand=ssh -W %h:%p alice@bastion.example.com' alice@target.example.com

Create a SOCKS listener on the server loopback interface. Other local users and processes on that server may access it; server policy must permit forwarding.

ssh -N -R 127.0.0.1:1080 -o ExitOnForwardFailure=yes alice@server.example.com

Configure encrypted SSH keepalive probes and a connection timeout. These detect an unresponsive peer; they do not guarantee reconnection.

ssh -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o ConnectTimeout=10 alice@server.example.com

Options and examples

-p portCommon

Connect to the specified server port.

Example
ssh -p 2222 alice@server.example.com
-i identity_fileCommon

Use the specified private key file; protect it and never share it.

Example
ssh -i ~/.ssh/id_ed25519 alice@server.example.com
-l login_name

Specify the remote login name.

Example
ssh -l alice server.example.com
-J destinationCommon

Connect through an SSH jump host.

Example
ssh -J alice@bastion.example.com alice@internal.example.com
-L address:port:host:hostportCommon

Forward a local listening port to a destination reached from the SSH server.

Example
ssh -N -L 127.0.0.1:15432:db.internal.example.com:5432 alice@server.example.com
-R address:port:host:hostportCommon

Forward a remote listening port to a destination reached from the local computer. Server policy can restrict binding.

Example
ssh -N -R 127.0.0.1:18080:127.0.0.1:8080 alice@server.example.com
-D address:portCommon

Create a local SOCKS listener. Configure each client to use it; this is not a VPN.

Example
ssh -N -D 127.0.0.1:1080 alice@server.example.com
-NCommon

Do not run a remote command; useful for forwarding only.

Example
ssh -N -D 127.0.0.1:1080 alice@server.example.com
-o option=valueCommon

Set an ssh_config option for this invocation. Forwarding setup success does not guarantee that a destination is reachable later.

Example
ssh -o ExitOnForwardFailure=yes alice@server.example.com
-F configfile

Use an alternative client configuration file.

Example
ssh -F ~/.ssh/lab_config alice@server.example.com
-v / -vvvCommon

Print diagnostic output; more v characters increase detail. Logs may contain sensitive connection information.

Example
ssh -vvv alice@server.example.com
-4 / -6

Use IPv4 only or IPv6 only, respectively.

Example
ssh -4 alice@server.example.com
-C

Request compression. It may not improve already compressed traffic.

Example
ssh -C alice@server.example.com
-T / -t

Disable or request a pseudo-terminal, respectively.

Example
ssh -t alice@server.example.com
-A

Enable agent forwarding. A compromised remote host can request signatures from the forwarded agent; use only with trusted hosts.

Example
ssh -A alice@server.example.com
-G

Print the effective client configuration after evaluating Host and Match rules.

Example
ssh -G lab
-V

Print the installed SSH client version.

Example
ssh -V

Authoritative references

Reviewed October 27, 2026