scp
Networking
Usage
scp [-P <port>] <src> <user>@<host>:<dest>Copies files over ssh in one shot; the port is a capital `-P`, the remote side needs a colon in its path, and for anything large or repeated rsync is better because it skips unchanged files and resumes.
Common flags
| Flag | Meaning |
|---|---|
| -P 2222 | Port, capital P. Lowercase -p means "preserve timestamps" here. |
| -r | Copy a directory and everything under it. |
| -i <key> | Use a specific private key. |
| -C | Compress in transit. |
| -3 | Copy between two remote hosts by routing through your machine. |
| -O | Use the old SCP protocol; OpenSSH 9 and later default to SFTP. |
Examples
scp -P 2222 build.tar.gz deploy@example.com:/tmp/Upload one file. The remote side needs the colon.
scp -r deploy@example.com:/var/log ./logsDownload a whole directory.
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 scp do?
Copies files over ssh in one shot; the port is a capital `-P`, the remote side needs a colon in its path, and for anything large or repeated rsync is better because it skips unchanged files and resumes.
Q. How do I type it?
scp [-P <port>] <src> <user>@<host>:<dest> — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man scp. This command sits under Networking.
Related commands
man page: man scp