scp
Quick Reference
Command Name:
scp
Category:
networking
Platform:
Linux/Unix
Basic Usage:
Common Use Cases
- 1
Secure file transfer
Transfer files securely between systems using SSH encryption
- 2
Remote backups
Copy important files or backups to remote servers
- 3
Deployment
Deploy code, configurations, and assets to production servers
- 4
Multi-server copying
Copy files between two remote systems without downloading locally
Syntax
scp [OPTION] [[user@]src_host:]file1 ... [[user@]dst_host:]file2
Options
Option | Description |
---|---|
-1 | Use protocol version 1 (deprecated) |
-2 | Use protocol version 2 (default and recommended) |
-4 | Force use of IPv4 addresses |
-6 | Force use of IPv6 addresses |
-B | Batch mode (prevents asking for passwords or passphrases) |
-C | Enable compression |
-c cipher | Select the cipher to use for encrypting the data transfer |
-F ssh_config | Specify an alternative SSH configuration file |
-i identity_file | Specify the file from which the identity (private key) is read |
-l limit | Limit bandwidth in Kbit/s |
-o ssh_option | Pass options to ssh in the format used in ssh_config |
-P port | Specify the port to connect to on the remote host |
-p | Preserve modification times, access times, and modes from the original file |
-q | Quiet mode - disable progress meter and warning/diagnostic messages |
-r | Recursively copy entire directories |
-S program | Specify the path to the ssh program |
-v | Verbose mode - display debugging messages |
Examples
How to Use These Examples
The examples below show common ways to use the scp
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
Basic Examples:
scp file.txt user@remote_host:/path/to/destination/
Copy a local file to a remote host.
scp user@remote_host:/path/to/file.txt local_directory/
Copy a remote file to the local system.
scp -r local_directory/ user@remote_host:/path/to/destination/
Copy an entire directory recursively to a remote host.
Advanced Examples:
scp -P 2222 file.txt user@remote_host:/path/to/destination/
Copy a file to a remote host using a non-standard SSH port (2222).
scp -C file.txt user@remote_host:/path/to/destination/
Enable compression during the transfer to speed up file transfers.
scp user1@host1:/path/file.txt user2@host2:/path/
Copy a file from one remote host to another remote host.