SCP, the Secure Copy Protocol, is a method for copying files between hosts over an SSH connection, so that both authentication and data transfer are encrypted. Among Internet protocols for file transfer, it is the minimal, command-line oriented option: one command copies a file or directory tree to or from a remote machine, with no interactive session and no directory browsing.
SCP has no formal standard. It inherits its wire format from the old BSD rcp command and simply runs that exchange inside an SSH channel. Since OpenSSH 9.0 (released in 2022), the scp client uses the SFTP protocol underneath by default, while keeping the familiar command syntax, because the legacy protocol has design flaws that cannot be fixed without breaking compatibility.
How the Secure Copy Protocol transfers files
A legacy SCP transfer works by starting a remote scp process through SSH. The local client opens an SSH session and executes a command such as scp -t /target (sink mode) or scp -f /source (source mode) on the server. The two processes then exchange a short text-based control stream followed by raw file bytes inside the encrypted channel.
Each file is announced by a control line that carries its permission bits, size and name, after which the content follows and is confirmed by a single acknowledgment byte. Directories are entered and left with dedicated messages, which allows recursive copies with the -r option.
The table below lists the control messages of the legacy protocol.
| Message | Meaning | Example content |
|---|---|---|
| C | Single file follows | Mode 0644, size 1024, file name |
| D | Enter a directory | Mode 0755, directory name |
| E | Leave the current directory | No arguments |
| T | Timestamps for the next item | Modification and access times |
| Status byte | Acknowledgment or error | 0 for success, 1 or 2 for errors |
Security comes entirely from SSH transport and authentication: key exchange, host key verification, ciphers and public-key or password login are handled by SSH. SCP itself adds no integrity checks beyond those of the SSH channel, which already provides a message authentication code on every packet.
SCP compared with SFTP, FTPS and rsync
SCP is the simplest SSH-based copy tool, but it offers fewer functions than its alternatives. The main competitor is SFTP, the SSH File Transfer Protocol, which runs over the same SSH connection but provides a full remote file system interface.
| Feature | SCP | SFTP | FTPS | Rsync over SSH |
|---|---|---|---|---|
| Transport | SSH, port 22 | SSH, port 22 | TLS, ports 21 and 990 | SSH, port 22 |
| Directory listing | No | Yes | Yes | Limited |
| Resume interrupted transfer | No | Yes | Yes | Yes |
| Delta transfer | No | No | No | Yes |
| Formal specification | None | IETF drafts | RFC 4217 | None |
| Firewall friendliness | High | High | Low, extra data channels | High |
For a one-off copy of a known file, SCP remains convenient. For large or repeated synchronization, rsync transfers only changed blocks, and for interactive management or scripted file operations, SFTP is the better choice. FTPS suits environments that already depend on FTP tooling but need TLS encryption.
Using the scp command in practice
The scp command uses a source and destination syntax in which remote paths are written as user@host:path. The same options apply whether the client speaks legacy SCP or SFTP underneath.
| Option | Function | Typical use |
|---|---|---|
-r | Copy directories recursively | Uploading a site build folder |
-P port | Connect to a non-default SSH port | Servers listening on port 2222 |
-i key | Use a specific private key | Automation with a deploy key |
-p | Preserve times and modes | Backups that keep timestamps |
-l limit | Limit bandwidth in Kbit/s | Copying over a shared link |
-O | Force the legacy SCP protocol | Old servers without SFTP |
-3 | Route a remote-to-remote copy through the client | Hosts that cannot reach each other |
Note that scp uses capital P for the port, unlike ssh, which uses lowercase -p. This inconsistency is a frequent source of failed commands in scripts.
Security weaknesses of the legacy SCP protocol
The legacy protocol is considered outdated and inflexible because the remote side runs a shell command and the client must trust what the server sends back. Several historical vulnerabilities followed from this design.
- Shell expansion of remote paths: file names are interpreted by the remote shell, so names with spaces or metacharacters need double quoting and can trigger unintended commands.
- Weak validation of server responses: in 2019, CVE-2018-20685 and related flaws showed that a malicious server could overwrite unexpected files or change directory permissions on the client.
- No partial resume or listing: an interrupted transfer must start again from the beginning.
- Restricted accounts are hard to build: SFTP-only accounts can be confined with
ForceCommand internal-sftp, while legacy SCP needs a remote shell.
For these reasons, the OpenSSH developers describe the legacy protocol as not recommended for new use. Keeping the scp command while letting it speak SFTP gives users the familiar syntax with stricter path handling on the server side.
When to choose SCP and when to avoid it
SCP fits quick, ad hoc transfers between machines that already allow SSH access. The decision table below summarizes typical situations.
| Situation | Recommended choice | Reason |
|---|---|---|
| Copy one config file to a server | scp | Short command, no setup |
| Nightly backup of a large tree | rsync over SSH | Transfers only changed data |
| Partner uploads to a shared host | SFTP with chroot | Restricted, auditable access |
| Very old embedded device | scp with -O | Device lacks an SFTP subsystem |
| Multi-gigabyte file over an unstable link | SFTP or rsync | Supports resuming |
Whatever tool is chosen, the host key fingerprint must be verified on first connection, because SCP inherits all of SSH’s protection and none of it applies if a forged host key is accepted.
Understanding it simply
SCP is like handing a sealed envelope to a trusted courier who already has a key to both buildings. You say which file to take and where to put it, and the courier carries it across without anyone along the way being able to read it.
It does one job only: it copies files safely from one computer to another. It cannot show you what is inside the other building or pick up where it stopped if interrupted. Newer versions quietly use a more capable courier service underneath, while you keep giving the same simple instructions.
Applied in practice
A systems administrator at a regional hospital needs to replace a TLS certificate on a Linux web server after renewal. From a hardened jump host, she runs scp -i ~/.ssh/deploy_ed25519 cert.pem admin@web01:/etc/ssl/site/, verifies the file with a checksum, and reloads the web server. The 4 KB file arrives in under a second over the existing SSH access, with no extra service exposed on the server.
The same team once used scp for nightly database dumps of about 40 GB, and transfers had to restart whenever the WAN link dropped. They moved that job to rsync over SSH with resumable partial files, which cut nightly transfer time by more than half, and kept scp for small, one-off administrative copies.