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

OptionWhat it does
-rCopy directories recursively.
-P PORTRemote SSH port (capital P, unlike ssh's -p).
-i KEYIdentity file, as with ssh.
-pPreserve times and modes.
-CCompress 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

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

tar

Create and extract archives: tar.gz, tar.bz2 — with the flag combinations finally explained.

ssh

Log into remote machines, run remote commands, use keys instead of passwords, and tunnel ports.

rsync

Sync directories locally or over SSH, transferring only what changed.

Want to build real fluency? The interactive course takes you through scp and every other essential command with guided, checked exercises.