Securely connect to a remote host over an encrypted SSH tunnel.
medium risk
ssh creates an encrypted connection to a remote machine. Key-based authentication (-i) is strongly preferred over passwords. -J enables jump host proxying through bastion servers. -L/-R set up local/remote port forwarding tunnels.
| Flag | Meaning |
|---|---|
-i | Specify private key file for authentication |
-p | Connect to a non-standard SSH port |
-L | Local port forwarding: tunnel a remote port to localhost |
-R | Remote port forwarding: expose local port on remote host |
-J | Jump/bastion host proxy |
-N | Do not execute a remote command (useful for tunnels) |
-v | Verbose mode for debugging connection issues |
ssh -i ~/.ssh/prod.pem [email protected]Connect to EC2 instance with a PEM key · explain & risk-check →ssh -L 5432:db.internal:5432 bastion.hostTunnel PostgreSQL through bastion to localhost:5432 · explain & risk-check →ssh -J bastion.host [email protected]Connect to private server through a jump/bastion host · explain & risk-check →Configure `~/.ssh/config` with Host aliases — replace `ssh -i key.pem -p 2222 [email protected]` with just `ssh prod`.
Reference text is hand-written and may be incomplete — check man ssh for your version. Test destructive commands on a non-production system first.