What is the basic syntax?
scp source target, where a remote side is written user@host:path:
scp nginx-site.conf ops@203.0.113.25:/tmp/ # upload scp ops@203.0.113.25:/var/log/nginx/error.log ./ # download scp -r ./site-build ops@203.0.113.25:/srv/staging/ # upload a folder
A path without a leading slash on the remote side is relative to the user's home folder. Everything travels inside SSH, so authentication, encryption and host checks are the same as for a login.
Which options do I use most?
| Option | Effect |
|---|---|
-P 2207 | Remote SSH port (capital P) |
-i ~/.ssh/ops_ed25519 | Use a specific key |
-r | Copy folders recursively |
-p | Keep modification times and modes |
-C | Compress in transit |
-l 200000 | Limit speed, in kilobits per second |
-J bastion | Hop through a jump host |
Host aliases from ~/.ssh/config work too, so scp backup.sql chi-db:/var/tmp/ picks up the address, port, user and key from the alias. Setting that up is covered in The SSH config file.
How does modern scp work under the hood?
Since OpenSSH 9.0, scp talks the SFTP protocol to the server instead of the old rcp-style protocol, which removed a class of file name parsing problems. For you, the command looks identical. If you ever connect to a very old device without SFTP support, -O switches back to the legacy mode. The protocol scp now relies on is explained in How SFTP works.
Can I copy between two remote machines?
scp -3 ops@203.0.113.25:/srv/exports/orders.csv ops@198.51.100.12:/srv/imports/
Without -3, the first remote machine connects directly to the second, which requires it to have a key for the second machine. With -3, data passes through your computer, so only you need access to both, but traffic flows twice through your connection. Between two of our machines in different cities, it is usually faster to log in to one and run scp or rsync from there, so the transfer stays on the data center networks.
How do I limit the impact on a busy server?
Use -l, which takes kilobits per second: -l 400000 is about 50 MB per second. Pair it with low CPU and I/O priority on the sending side if the copy competes with production work. Remember that outgoing data counts toward the sending machine's 15 TB monthly allowance, while the receiving machine takes it in free.
What errors come up?
- "Permission denied (publickey)": the same key problem as with ssh; see Fix "Permission denied (publickey)".
- "scp: /srv/staging/: Permission denied": the remote user cannot write there. Copy to
/tmpand move with sudo, or fix ownership. - "No such file or directory" with wildcards: quote remote globs, as in
'ops@host:/var/log/app/*.log', so your local shell does not expand them. - Very slow copies of many small files: each file costs round trips; archive first with tar, or use rsync.
When should I use rsync or sftp instead?
scp is ideal for a few files, once. Switch to rsync when copies repeat, are large or might be interrupted: it transfers only differences and resumes cleanly, as shown in Rsync over SSH. Use sftp when you want to browse the remote side interactively before deciding what to fetch; see Use SFTP step by step.
Can I stream instead of copying a file?
Yes, with plain ssh and a pipe, which avoids a temporary file on either side: pg_dump -Fc shop | ssh ops@198.51.100.12 'cat > /backup/shop-$(date +%F).dump'. This is often the cleanest way to move a database dump from a machine with little free disk.
For very large single files, compare scp with rsync's --partial mode before committing to a long copy, since only rsync can pick up halfway through after a dropped connection.
Keep Reading
Rsync over SSH
Copy and mirror folders between machines with rsync over SSH: trailing slashes, dry runs, custom ports, sudo on the far side and bandwidth caps.
OpenUse SFTP step by step
Connect, browse, upload, download and resume with the sftp client, run batch jobs and use graphical clients on Windows and macOS.
OpenThe SSH config file
Turn long ssh command lines into short aliases with ~/.ssh/config: hosts, ports, keys, jump hosts, keepalives and connection sharing.
OpenSFTP commands reference
Every sftp prompt command worth knowing, grouped by job: navigation, transfers, resumes, file management, links, disk space and local escapes.
OpenFAQ
Quick Answers
Run scp file user@host:/path/. Use -P for a non-default port.
Add -r, for example scp -r ./dir user@host:/srv/.
Capital -P; lowercase -p is taken by preserving times and modes.
Yes. Use -3 to route data through your computer, or let one server connect to the other.
Yes. Since OpenSSH 9.0 it uses the SFTP protocol under the hood.