ssh
Networking
Usage
ssh [-p <port>] <user>@<host> [command]Opens an encrypted shell on another machine; ssh flatly refuses a private key that others can read, so `chmod 600` it, and the port is `-p` here but `-P` in scp and sftp.
Common flags
| Flag | Meaning |
|---|---|
| -p 2222 | Port. Note that scp and sftp spell the same thing -P. |
| -i ~/.ssh/id_ed25519 | Use a specific private key. |
| -L 8080:localhost:80 | Local forward: your port 8080 reaches the remote side. |
| -R 9000:localhost:3000 | Remote forward: their port 9000 reaches your machine. |
| -D 1080 | A local SOCKS proxy tunnelled through the host. |
| -J <bastion> | Jump through a bastion host in one command. |
| -N -f | No remote command, go to the background. The pair used for tunnels. |
| -v / -vvv | Show the handshake, which is how you find out why a key was refused. |
| -o <Option>=<value> | Any ssh_config setting for this one connection. |
Examples
ssh -p 2222 deploy@example.comLog in on a non-standard port.
ssh -N -L 5432:localhost:5432 deploy@db.example.comReach the remote database as if it were local.
ssh -vvv git@github.comSee exactly which keys were offered and rejected.
When a connection fails, these narrow down how far it got — name not resolving, no route, or a blocked port.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does ssh do?
Opens an encrypted shell on another machine; ssh flatly refuses a private key that others can read, so `chmod 600` it, and the port is `-p` here but `-P` in scp and sftp.
Q. How do I type it?
ssh [-p <port>] <user>@<host> [command] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
9 are listed here; the full set is in man ssh. This command sits under Networking.
Related commands
man page: man ssh