Skip to main content

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
Direct Remote-to-Remote

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

FlagDescriptionExample
-rCopy directories recursivelyscp -r ./dir/ user@host:/path/
-P PORTConnect on a custom SSH portscp -P 2222 file user@host:/path/
-i KEYUse a specific SSH identity filescp -i ~/.ssh/mykey file user@host:/path/
-CEnable compression during transferscp -C largefile user@host:/path/
-l LIMITBandwidth limit in Kbit/sscp -l 5000 file user@host:/path/
-pPreserve modification time, access time, modesscp -p file user@host:/path/
-qQuiet mode (suppress progress meter)scp -q file user@host:/path/
-vVerbose mode (SSH debug output)scp -v file user@host:/path/
-F CONFIGUse a specific SSH config filescp -F ~/.ssh/custom_config file user@host:/path/
-c CIPHERSelect encryption cipherscp -c aes256-ctr file user@host:/path/
-o OPTIONPass SSH options directlyscp -o StrictHostKeyChecking=no file user@host:/path/
-3Route remote-to-remote via local hostscp -3 userA@a:/f userB@b:/f
-4Force IPv4 onlyscp -4 file user@host:/path/
-6Force IPv6 onlyscp -6 file user@host:/path/
-S PROGRAMUse a specific SSH programscp -S /usr/bin/ssh file user@host:/path/
-OUse legacy SCP protocol (not SFTP)scp -O file user@host:/path/
-D SFTP_PATHConnect directly to a local SFTP serverscp -D /usr/lib/sftp-server file host:/path/
-J JUMPProxyJump through a bastion hostscp -J bastion file user@host:/path/
-BBatch mode (prevents password prompts)scp -B file user@host:/path/
-TDisable strict filename checkingscp -T file user@host:/path/
-sUse 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.