scp (secure copy) copies files between computers over SSH. If you can SSH into a server, you can scp files to and from it — no extra software or open ports needed. It’s the quickest way to upload a config file, download a backup or move a dump between servers.
Syntax
scp [options] SOURCE DESTINATION
A remote location is written user@host:path. A local path has no colon.
Upload a file to a server
scp backup.sql.gz [email protected]:/root/
scp ./nginx.conf [email protected]:/home/deploy/nginx.conf.new
If the remote path is relative, it starts in the user’s home directory: user@host:uploads/ = /home/user/uploads/.
Download a file from a server
scp [email protected]:/var/backups/db-2026-11-04.sql.gz .
scp [email protected]:/var/log/nginx/error.log ~/Downloads/
The . means “the current directory”.
Copy directories
scp -r ./site [email protected]:/var/www/
scp -r [email protected]:/etc/nginx ./nginx-backup
-r copies recursively. For large directory trees or repeated copies, rsync is much better: it only transfers changes and can resume.
Multiple files and wildcards
scp file1.txt file2.txt user@host:/tmp/
scp 'user@host:/var/log/nginx/*.log' ./logs/
Quote remote wildcards so your local shell doesn’t try to expand them.
Custom port and key
scp -P 2222 file.txt user@host:/tmp/ # capital P for port (ssh uses lowercase -p)
scp -i ~/.ssh/deploy_key file.txt user@host:/tmp/
Better: put host settings in ~/.ssh/config once, and scp (like ssh) uses them automatically:
Host web1
HostName 203.0.113.10
User deploy
Port 2222
IdentityFile ~/.ssh/deploy_key
scp backup.tar.gz web1:/home/deploy/
More in the SSH config file guide.
Server to server
scp -3 user@old-server:/var/backups/site.tar.gz user@new-server:/var/backups/
Without -3, the first server connects directly to the second — which only works if it has credentials for it. With -3, data flows through your computer, using your keys for both. Slower, but no key setup between the servers.
Other useful options
| Option | Meaning |
|---|---|
-r |
Recursive (directories) |
-P port |
SSH port |
-i key |
Identity (private key) file |
-p |
Preserve modification times and modes |
-C |
Compress in transit |
-l kbit |
Limit bandwidth in Kbit/s (-l 8000 ≈ 1 MB/s) |
-q |
Quiet, no progress meter |
-v |
Verbose — shows the SSH negotiation, useful for debugging |
-J jump |
Go through a jump host |
Windows and macOS
- macOS and Linux include scp in the terminal.
- Windows 10/11 include the OpenSSH client:
scpworks in PowerShell and Command Prompt, with paths likeC:\Users\you\file.txt. - For drag-and-drop, use an SFTP client: WinSCP (Windows), FileZilla or Cyberduck — they connect to the same SSH server using the SFTP protocol.
scp and SFTP under the hood
Since OpenSSH 9.0, the scp command uses the SFTP protocol by default instead of the legacy SCP protocol, which had design flaws around filename handling. Command usage is unchanged. If you connect to a very old server without SFTP support, add -O to force the legacy protocol.
Troubleshooting
Permission denied (publickey) — the same issue as with SSH; fix your key setup first: SSH Permission denied (publickey).
scp: /var/www/site/file: Permission denied — you connected fine, but your remote user can’t write there. Upload to your home directory, then move it with sudo on the server:
scp file.conf user@host:/tmp/
ssh user@host 'sudo mv /tmp/file.conf /etc/nginx/conf.d/'
ssh: connect to host … port 22: Connection refused — SSH runs on another port (use -P) or the firewall blocks it. See SSH connection refused.
Transfer is slow — scp is single-stream and encrypts everything; that’s usually fine. For many small files, pack them first with tar or use rsync.
Output from .bashrc breaks the transfer — if the remote shell prints text on login (echo statements in .bashrc), file transfers can fail. Guard those lines so they only run in interactive shells.
Quick reference
scp file user@host:/path/ # upload
scp user@host:/path/file . # download
scp -r dir user@host:/path/ # upload a directory
scp -P 2222 file user@host:/path/ # custom port
scp -i key.pem file user@host:/path/ # specific key
scp -3 a@host1:/f b@host2:/path/ # server to server via you
New to SSH? Start with connecting to your VPS over SSH and creating SSH keys.