The scp command in Linux
scp (secure copy) copies files between machines over SSH, with cp-like syntax: source, then destination, either side allowed to be remote (user@host:path). For a single file it is the fastest thing to type; for directories, repeated syncs or resumable transfers, rsync is the stronger tool built on the same transport.
How scp works
scp opens an SSH connection and runs a copy protocol over it, inheriting all of SSH's machinery: your keys, your config-file Host aliases, the encryption. Modern OpenSSH quietly reimplemented scp on top of SFTP (the structured file-transfer subsystem), retiring the 1983-era RCP protocol while keeping the beloved command-line syntax intact.
What scp deliberately lacks explains when to leave it: no delta transfer (every byte travels every time), no resume, no deletion mirroring, no dry run. It is cp with a network in the middle — perfect at that, and exactly why rsync (same transport, smarter payload) takes over the moment transfers repeat or trees get large.
Syntax
scp [OPTIONS] SOURCE DEST Common options
| Option | What it does |
|---|---|
-r | Copy directories recursively. |
-P PORT | Remote SSH port (capital P, unlike ssh's -p). |
-i KEY | Identity file, as with ssh. |
-p | Preserve times and modes. |
-C | Compress in transit. |
How to use scp: examples
$ scp report.pdf user@server:/tmp/ Push a file to a remote directory.
$ scp user@server:/var/log/app.log . Pull a remote file into the current directory.
$ scp -P 2222 -r site/ user@server:/var/www/ Recursive copy over a custom port.
$ scp user@a:/data/file user@b:/data/ Remote-to-remote in one command (traffic relays through your machine by default).
Real-world use cases for scp
The quick artifact grab
A colleague needs the log right now: scp server:/var/log/app/error.log . and it is on your desk in one line — SSH config aliases make it scp web1:/var/log/... with no user or IP to remember.
Seeding a new machine
First contact with a fresh server: scp -r dotfiles/ new-host:~/ pushes your environment before the first real session. For anything beyond this one-shot size, the same trip belongs to rsync.
Pro tips and common mistakes
- Port is -P (capital) in scp — the lowercase -p preserves timestamps. Everyone burns this once.
- Your ~/.ssh/config Host aliases work in scp too; invest in the config once, harvest everywhere.
- Repeating a transfer or copying trees? Stop mid-keystroke and type rsync instead.
Frequently asked questions about scp
Why -P for the port when ssh uses -p?
Historical accident: scp inherited -p for "preserve" from cp, so the port needed another letter. Everyone trips on it once.
Can scp resume an interrupted transfer?
No — that is rsync -P territory. An interrupted scp starts over.
Permission denied writing to the destination?
Your SSH user lacks write permission there. Copy to /tmp and sudo mv on the server, or fix ownership — scp cannot sudo on the far side.
Related commands
Create and extract archives: tar.gz, tar.bz2 — with the flag combinations finally explained.
sshLog into remote machines, run remote commands, use keys instead of passwords, and tunnel ports.
rsyncSync directories locally or over SSH, transferring only what changed.