Basic Copy
The most common SCP operations are copying files to a remote server, downloading files from a remote server, and copying between two remote servers.
Syntax
scp [OPTIONS] SOURCE DESTINATION
A remote path always follows the format user@host:/path/to/file.
Copy Patterns
1. Local to Remote
Push a file from your machine to a remote server.
Command:
scp ./backup.tar.gz deploy@192.168.1.100:/opt/backups/
Output:
backup.tar.gz 100% 250MB 45.2MB/s 00:05
2. Remote to Local
Pull a file from a remote server to your machine.
Command:
scp deploy@192.168.1.100:/var/log/nginx/access.log ./logs/
Output:
access.log 100% 12MB 38.7MB/s 00:00
3. Remote to Remote
Copy a file directly between two remote servers (your machine acts as a relay).
Command:
scp user@server-a:/data/export.csv user@server-b:/imports/
Output:
export.csv 100% 500KB 22.1MB/s 00:00
By default, SCP routes remote-to-remote traffic through your local machine. Use the -3 flag to make this explicit, or use -O to force the legacy SCP protocol which may route directly in some configurations.
All Key Flags
| Flag | Description | Example |
|---|---|---|
-r | Copy directories recursively | scp -r ./dir/ user@host:/path/ |
-P PORT | Connect on a custom SSH port | scp -P 2222 file user@host:/path/ |
-i KEY | Use a specific SSH identity file | scp -i ~/.ssh/mykey file user@host:/path/ |
-C | Enable compression during transfer | scp -C largefile user@host:/path/ |
-l LIMIT | Bandwidth limit in Kbit/s | scp -l 5000 file user@host:/path/ |
-p | Preserve modification time, access time, modes | scp -p file user@host:/path/ |
-q | Quiet mode (suppress progress meter) | scp -q file user@host:/path/ |
-v | Verbose mode (SSH debug output) | scp -v file user@host:/path/ |
-F CONFIG | Use a specific SSH config file | scp -F ~/.ssh/custom_config file user@host:/path/ |
-c CIPHER | Select encryption cipher | scp -c aes256-ctr file user@host:/path/ |
-o OPTION | Pass SSH options directly | scp -o StrictHostKeyChecking=no file user@host:/path/ |
-3 | Route remote-to-remote via local host | scp -3 userA@a:/f userB@b:/f |
-4 | Force IPv4 only | scp -4 file user@host:/path/ |
-6 | Force IPv6 only | scp -6 file user@host:/path/ |
-S PROGRAM | Use a specific SSH program | scp -S /usr/bin/ssh file user@host:/path/ |
-O | Use legacy SCP protocol (not SFTP) | scp -O file user@host:/path/ |
-D SFTP_PATH | Connect directly to a local SFTP server | scp -D /usr/lib/sftp-server file host:/path/ |
-J JUMP | ProxyJump through a bastion host | scp -J bastion file user@host:/path/ |
-B | Batch mode (prevents password prompts) | scp -B file user@host:/path/ |
-T | Disable strict filename checking | scp -T file user@host:/path/ |
-s | Use SFTP subsystem for transfers (default in newer OpenSSH) | scp -s file user@host:/path/ |
Examples with Output
1. Copy with Progress (Default)
Command:
scp ./database-dump.sql admin@db-server:/backups/
Output:
database-dump.sql 100% 150MB 42.3MB/s 00:03
2. Copy with Quiet Mode
Command:
scp -q ./config.yml admin@web-server:/etc/app/
Output:
(no output — quiet mode suppresses progress)
3. Copy with Verbose Debugging
Command:
scp -v ./script.sh admin@host:/tmp/
Output:
Executing: program /usr/bin/ssh host admin, user admin, command scp -t /tmp/
OpenSSH_8.9p1, OpenSSL 3.0.2
debug1: Reading configuration data /home/user/.ssh/config
debug1: Connecting to host [192.168.1.100] port 22.
debug1: Connection established.
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/user/.ssh/id_ed25519
debug1: Server accepts key: /home/user/.ssh/id_ed25519
debug1: Authentication succeeded (publickey).
script.sh 100% 2048 1.2MB/s 00:00
4. Copy with Bandwidth Limit
Command:
scp -l 8000 ./large-archive.tar.gz admin@host:/data/
Output:
large-archive.tar.gz 100% 2048MB 1.0MB/s 34:08
5. Preserve File Attributes
Command:
scp -p ./important-doc.pdf admin@host:/shared/
Output:
important-doc.pdf 100% 15MB 40.5MB/s 00:00
What's Next?
Learn how to transfer entire directories in Directory Transfer.