Catalog / SCP Cheat Sheet
SCP Cheat Sheet
A comprehensive guide to using the Secure Copy (SCP) command for secure file transfer between systems. This cheat sheet covers basic usage, advanced options, and practical examples for efficient remote file management.
SCP Basics
Basic Syntax
|
Where |
And |
Copying a Local File to a Remote System
Copying a single file: |
Copying multiple files: |
Copying a Remote File to a Local System
Copying a single file: |
Copying multiple files: |
Advanced SCP Options
Port Specification
|
Specifies the port to connect to on the remote host. Useful when the SSH server listens on a non-standard port. Example: |
Recursive Copy
|
Recursively copies entire directories. Example: |
Preserving Modification Times and Modes
|
Preserves modification times, access times, and modes from the original file. Example: |
Using a Specific Cipher
|
Selects the cipher to use for encrypting the data transfer. Check available ciphers with Example: |
Limiting Bandwidth
|
Limits the bandwidth used by SCP, specified in Kbit/s. Example: |
Security Considerations
Verifying Host Identity
SCP relies on SSH for secure communication. Ensure you verify the host identity when connecting to a new server to avoid man-in-the-middle attacks. |
Check the host key fingerprint against a known trusted source. |
Using SSH Keys
Using SSH keys for authentication is more secure than password-based authentication. Generate an SSH key pair using |
Copy the public key to the remote server using |
You can specify the identity file with the |
Disabling Password Authentication
For increased security, disable password authentication on the SSH server after setting up SSH key authentication. Edit |
Restart the SSH service after making changes: |
Practical Examples
Copying Files Between Two Remote Servers
To copy directly between two remote servers, you can use a local machine as an intermediary, or use SSH tunneling. |
Copying from remote1 to remote2 via local: |
Using SCP with Wildcards
Wildcards can be used to copy multiple files at once. Be careful to escape them properly to prevent local shell expansion. Example: |
SCP with Verbose Output
Use the Example: |