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 fileUse a specific private key.
-p PORTConnect to a custom port.
-L LPORT:HOST:RPORTLocal port forwarding.
-R RPORT:HOST:LPORTRemote port forwarding.
-J hostProxyJump via a bastion host.
-NDo not execute remote command (tunneling only).
Usage Examples
Connect with Key
Login using a specific key.
ssh -i ~/.ssh/id_ed25519 user@serverCustom Port
SSH on port 2222.
ssh -p 2222 user@serverLocal Port Forward
Forward local 5432 to remote DB.
ssh -L 5432:localhost:5432 user@serverJump Host
Connect via bastion.
ssh -J user@bastion user@internalRemote 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-hostCommon 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.