ssh

Secure shell for remote login, tunneling, and secure command execution.

Synopsis

ssh [options] user@host

When to Use It

Use ssh for routine server access, safe command execution on remote hosts, database tunnels from your laptop, or hopping through bastion machines into private infrastructure.

Core Options

-i file

Use a specific private key.

-p PORT

Connect to a custom port.

-L LPORT:HOST:RPORT

Local port forwarding.

-R RPORT:HOST:LPORT

Remote port forwarding.

-J host

ProxyJump via a bastion host.

-N

Do not execute remote command (tunneling only).

Usage Examples

Connect with Key

Login using a specific key.

ssh -i ~/.ssh/id_ed25519 user@server

Custom Port

SSH on port 2222.

ssh -p 2222 user@server

Local Port Forward

Forward local 5432 to remote DB.

ssh -L 5432:localhost:5432 user@server

Jump Host

Connect via bastion.

ssh -J user@bastion user@internal

Remote Command

Run a single command without opening an interactive shell.

ssh user@server 'uptime && df -h'

Tunnel Only

Open a local tunnel without starting a shell session.

ssh -N -L 5432:localhost:5432 user@db-host

Common Mistakes

  • The uppercase or lowercase port flags differ across tools: ssh uses lowercase -p, while scp uses uppercase -P.
  • A tunnel can appear broken when the remote service binds to a different host or port than the one you forwarded.
  • Authentication failures are often key-permission problems or the wrong user, not always the wrong server.

Related

Built for builders.