scp Command Cheat Sheet
scp (Secure Copy) copies files between hosts on a network. It uses SSH for data transfer, and uses the same authentication and provides the same security as SSH.
Note: Modern scp usually uses the SFTP protocol under the hood, but the CLI syntax remains distinct.
Synopsis
scp [Option] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2
Basic Copying
Local to Remote (Upload)
scp file.txt user@remote:/home/user/
Remote to Local (Download)
scp user@remote:/var/log/syslog ./local_syslog
Remote to Remote (3-way copy)
Transfer a file from Server A to Server B, running the command from your laptop. (Requires Agent Forwarding or explicit auth).
scp user@serverA:/file.txt user@serverB:/backup/
Directories
Recursive Copy (-r)
Copies the directory and its entire content.
scp -r project_folder/ user@remote:/var/www/
Performance & Attributes
Preserve Attributes (-p)
Preserves modification times, access times, and modes from the original file.
scp -p file.txt user@remote:/tmp/
Compression (-C)
Enables compression (gzip) during transfer. Good for slow networks or text files.
scp -C large_log.txt user@remote:/tmp/
Limit Bandwidth (-l)
Limit the used bandwidth, specified in Kbit/s.
# Limit to 1000 Kbit/s (approx 125 KB/s)
scp -l 1000 video.mp4 user@remote:/tmp/
Connection Options
Specify Port (-P)
Note: It's capital -P (unlike ssh which uses -p).
scp -P 2222 file.txt user@remote:/tmp/
Using Identity File (-i)
scp -i ~/.ssh/my_key.pem file.txt user@aws-instance:/tmp/
Quiet Mode (-q)
Disable the progress meter and warning/diagnostic messages.
scp -q file.txt user@remote:/tmp/
scp vs rsync
| Feature | scp |
rsync |
|---|---|---|
| Simple usage | Easier | Slightly more complex flags |
| Resuming | No (mostly) | Yes (excellent) |
| Speed | Copies everything | Copies only differences (Delta) |
| Symlinks | Follows (usually) | Preserves (-l) |
Recommendation: Use scp for quick, one-off single file copies. Use rsync for everything else (directories, large files, mirroring).
Troubleshooting
"Permission denied (publickey)"
The remote server rejected your key. Check permissions on ~/.ssh/authorized_keys on the remote side.
"scp: /path/: Is a directory"
You forgot the -r flag.
"Host key verification failed"
The remote server's fingerprint changed. Remove the old entry from ~/.ssh/known_hosts using ssh-keygen -R hostname.