What is SCP
SCP (Secure Copy Protocol) is a command-line utility that copies files between hosts on a network. It uses SSH for data transfer and provides the same authentication and security as SSH.
Quick Summary
SCP is the simplest way to copy files securely between two machines. If you can SSH into a server, you can use SCP to transfer files to and from it.
How SCP Works
sequenceDiagram
participant L as Local Machine
participant S as SSH Layer
participant R as Remote Server
L->>S: Authenticate (key or password)
S->>R: Establish encrypted tunnel
L->>R: Transfer file data (encrypted)
R-->>L: Confirm receipt
- SCP initiates an SSH connection to the remote host.
- After authentication, it opens an encrypted channel.
- File data is streamed through this channel.
- The connection closes once the transfer completes.
Key Characteristics
| Feature | Detail |
|---|---|
| Protocol | SSH (port 22 by default) |
| Encryption | Always encrypted in transit |
| Authentication | SSH keys or password |
| Resume | Not supported (restarts from scratch) |
| Delta Transfer | Not supported (always full copy) |
| Compression | Optional (-C flag) |
| Recursive | Supported (-r flag) |
SCP vs SFTP vs Rsync
| Criteria | SCP | SFTP | Rsync |
|---|---|---|---|
| Speed | Fast (simple protocol) | Moderate | Fast (delta only) |
| Resume Transfers | No | Yes | Yes |
| Interactive Mode | No | Yes (shell-like) | No |
| Delta Sync | No | No | Yes |
| Scriptability | Excellent | Good | Excellent |
| Best For | Quick one-off copies | Interactive file management | Recurring syncs |
When to Choose SCP
- You need a single, quick file transfer and nothing more.
- The remote host only has basic OpenSSH (no rsync installed).
- You are scripting a simple deploy step where the file changes completely each time.
When to Avoid SCP
- Large recurring backups → use
rsync(delta transfer saves bandwidth). - Cloud storage → use
rclone. - Resumable uploads → use
sftporrsync --partial.
Basic Syntax
scp [OPTIONS] SOURCE DESTINATION
Where SOURCE and DESTINATION can be:
- A local path:
/home/user/file.txt - A remote path:
user@host:/path/to/file.txt
Examples with Output
1. Check SCP Availability
Command:
scp 2>&1 | head -1
Output:
usage: scp [-346ABCOpqRrsTv] [-c cipher] [-D sftp_server_path] [-F ssh_config]
2. Check SSH Version (SCP depends on it)
Command:
ssh -V
Output:
OpenSSH_8.9p1 Ubuntu-3ubuntu0.10, OpenSSL 3.0.2 15 Mar 2022
What's Next?
Continue to Installation and Setup to configure SSH keys for password-less SCP transfers.