ssh
Overview
ssh (OpenSSH client) creates encrypted sessions to a remote host for shell access, command execution, port forwarding, and tunneling. Pair with scp/sftp/rsync for files.
Syntax
ssh [options] [user@]host [command]
ssh -J jump user@hostCommon Options
| Option | Description |
|---|---|
-i key |
Private key identity file |
-p port |
Remote port (default 22) |
-L / -R / -D |
Local / remote / dynamic port forwards |
-N |
No remote command (forward only) |
-f |
Background after auth |
-A |
Agent forwarding (use sparingly) |
-J host |
ProxyJump |
-o Opt=Val |
Config override |
-v / -vv |
Debug auth/connection |
-t |
Force TTY |
-C |
Compression |
Key Use Cases
- Remote administration
- Run one-shot remote commands
- Port forwards to private services
- Jump-host (bastion) workflows
Safety
- Prefer keys over passwords; disable agent forwarding except when required.
- Verify host keys on first connect; investigate changed key warnings (possible MITM).
- Do not forward agent (
-A) to untrusted hosts.
Examples with Explanations
Login
ssh alice@server.example.com
ssh -i ~/.ssh/id_ed25519 alice@server.example.comRemote command
ssh alice@server 'hostname; uptime'Custom port / options
ssh -p 2222 -o ConnectTimeout=5 alice@serverProxyJump via bastion
ssh -J bastion.example.com alice@internal.example.com
# config equivalent: ProxyJump bastion.example.comLocal port forward (remote DB to local)
ssh -N -L 5432:127.0.0.1:5432 alice@server
# then connect local clients to localhost:5432Dynamic SOCKS proxy
ssh -N -D 1080 alice@serverConfig file (~/.ssh/config)
Host prod
HostName 203.0.113.10
User deploy
IdentityFile ~/.ssh/prod_ed25519
ForwardAgent nossh prodVerbose auth debug
ssh -vv alice@serverCommon Usage Patterns
Copy key (once)
ssh-copy-id -i ~/.ssh/id_ed25519.pub alice@serverEscape sequence (client)
Enter ~ . disconnects a wedged session; Enter ~ ? lists escapes.
Notes & Pitfalls
user@hostdefaults user to local username if omitted.
- Global known hosts:
~/.ssh/known_hosts.
- Multiplexing:
ControlMaster/ControlPathspeeds repeated connections.
Additional Resources
man ssh,man ssh_config