network
ssh
Opens an encrypted shell session to a remote host. Also runs single remote commands and can tunnel arbitrary TCP ports.
ssh [OPTIONS] [user@]host [command] Common flags
| Flag | Purpose |
|---|---|
| -p | Connect to a non-default port |
| -i | Use the given private key file |
| -L | Local port forwarding: [bind:]port:host:hostport |
| -R | Remote port forwarding back to the client |
| -N | Do not execute a remote command (useful for tunnels) |
| -f | Go to background just before command execution |
| -v | Verbose -- invaluable for debugging auth issues |
Examples
ssh user@server Interactive login
ssh -p 2222 -i ~/.ssh/id_ed25519 deploy@host Custom port and identity file
ssh user@server 'df -h /var' Run a single remote command
ssh -NL 5432:localhost:5432 [email protected] Tunnel a remote Postgres port to localhost
Gotcha
The remote command runs in a non-interactive shell -- your ~/.bashrc may not be sourced, so full paths for tools are safer.
Related commands
rsync
Efficient file synchronizer that copies only the differences between source and destination. Works locally or over SSH.
curl
Transfers data to or from a server across many protocols including HTTP, HTTPS, FTP, and SCP. The Swiss Army knife of ad-hoc HTTP requests.
dig
Queries DNS servers for records and diagnostics. Preferred over nslookup for scripting and detailed troubleshooting.