Home·Terminal commands

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

FlagMeaning
-P 2222Port, capital P. Lowercase -p means "preserve timestamps" here.
-rCopy a directory and everything under it.
-i <key>Use a specific private key.
-CCompress in transit.
-3Copy between two remote hosts by routing through your machine.
-OUse 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 ./logs

Download 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