LFCA 53 ๐ง Copying Files โ scp
The scp command copies files between hosts over SSH. It uses the SSH’s authentication and encryption, so the transfer is secure without any additional configuration. The command is the cp‘s remote’s version: the same source-and-destination shape, the same recursive’s -r, but the either side can be the remote’s and the transport is the encrypted’s. It is the tool for the one-off’s transfer โ the config’s file’s push, the log’s pull, the directory’s copy โ and it is the simplest’s way to move the files across the hosts. This chapter covers the scp‘s syntax, the upload’s, the download’s, the recursive’s, the port’s, the key’s, the agent’s, the ~/.ssh/config‘s integration, the performance’s versus the rsync‘s, the security’s, and the patterns that make the remote’s copy reliable. It builds on LFCA 51 and 52 and prepares the ground for the rsync‘s material.
Key point: The scp source destination is the basic’s, and the remote’s is the [user@]host:path‘s. The scp file user@host:/path is the upload’s, and the scp user@host:/path file is the download’s. The -r is the recursive’s, the -P is the port’s (the uppercase’s), the -i is the key’s, the -p is the preserve’s (the timestamps’s and the modes’s), the -C is the compression’s, the -q is the quiet’s, the -v is the verbose’s. The scp uses the SSH’s authentication, so the ~/.ssh/config‘s, the ssh-agent‘s, and the keys’s are the same’s. The scp is the simple’s, and the rsync‘s is the delta’s. The scp is deprecated in the OpenSSH 9.0 in favor of the sftp‘s and the rsync‘s, but the scp is still the ubiquitous’s.
Why the scp matters
The scp is the simple’s, and the simple’s is the universal’s.
The scp‘s case. The scp‘s is the one-off’s, the quick’s, the script’s. The scp‘s is the single’s file’s, and the single’s is the fast’s.
The scp‘s simplicity. The scp‘s is the cp‘s, and the cp‘s is the familiar’s. The scp‘s is the source’s and the destination’s, and the destination’s is the remote’s. The two are the pair, and the pair is the design’s.
The scp‘s transport. The scp‘s transport is the SSH’s, and the SSH’s is the encrypted’s. The scp‘s is the authentication’s, and the authentication’s is the SSH’s. The two are the pair, and the pair is the security’s.
Why the scp matters for the config’s. The scp matters for the config’s, and the config’s is the ~/.ssh/config‘s. The scp‘s is the alias’s, and the alias’s is the convenient’s. The two are the pair, and the pair is the design’s.
Why the scp matters for the agent’s. The scp matters for the agent’s, and the agent’s is the passphrase’s cache’s. The scp‘s is the agent’s, and the agent’s is the passwordless’s. The two are the pair, and the pair is the design’s.
Why the scp matters for the script’s. The scp matters for the script’s, and the script’s is the automation’s. The scp‘s is the cron’s, the backup’s, the deploy’s. The two are the pair, and the pair is the efficiency’s.
Why the scp matters for the simple’s. The scp matters for the simple’s, and the simple’s is the universal’s. The scp‘s is the everywhere’s, and the everywhere’s is the compatible’s. The two are the pair, and the pair is the design’s.
Why the scp‘s the deprecation matters. The scp‘s the deprecation is the OpenSSH 9.0’s, and the OpenSSH 9.0’s is the sftp’s. The scp‘s is the legacy’s, and the legacy’s is the compatibility’s. The two are the pair, and the pair is the transition’s.
Why the
scpis the ubiquitous’s. Thescpis the ubiquitous’s, and the ubiquitous’s is the everywhere’s. Thescp‘s is the simple’s, and the simple’s is the universal’s. The two are the pair, and the pair is the design’s.
The scp‘s basic usage
The scp source destination is the basic’s, and the basic’s is the copy’s.
scp file.txt user@example.com:/tmp/
The scp file.txt user@example.com:/tmp/ is the upload’s, and the upload’s is the local’s-to-remote’s. The file.txt is the source’s, and the user@example.com:/tmp/ is the destination’s. The two are the pair, and the pair is the design’s.
Why the scp‘s basic matters. The scp‘s basic is the cp‘s, and the cp‘s is the familiar’s. The scp‘s is the source’s and the destination’s, and the destination’s is the remote’s. The two are the pair, and the pair is the design’s.
The remote’s syntax. The [user@]host:path is the remote’s, and the remote’s is the colon’s.
user@example.com:/tmp/
โ โ โ
โ โ โโโ the path's
โ โโโ the host's
โโโ the user's (the optional's)
The user@example.com:/tmp/ is the remote’s, and the remote’s is the colon’s. The user’s is the optional’s, and the optional’s is the local’s’s default’s. The two are the pair, and the pair is the design’s.
Why the remote’s syntax matters. The remote’s syntax is the colon’s, and the colon’s is the distinction’s. The host:path‘s is the remote’s, and the /path‘s is the local’s. The two are the pair, and the pair is the design’s.
The download’s. The scp user@example.com:/tmp/file.txt . is the download’s, and the download’s is the remote’s-to-local’s.
scp user@example.com:/tmp/file.txt .
The scp user@example.com:/tmp/file.txt . is the download’s, and the download’s is the remote’s-to-local’s. The . is the current’s, and the current’s is the destination’s. The two are the pair, and the pair is the design’s.
Why the download matters. The download is the remote’s-to-local’s, and the remote’s-to-local’s is the pull’s. The scp user@host:/path .‘s is the pull’s, and the pull’s is the common’s. The two are the pair, and the pair is the design’s.
The both’s remote’s. The scp user1@host1:/path user2@host2:/path is the both’s, and the both’s is the host’s-to-host’s.
scp user1@host1:/tmp/file.txt user2@host2:/tmp/
The scp user1@host1:/tmp/file.txt user2@host2:/tmp/ is the both’s, and the both’s is the host’s-to-host’s. The two are the pair, and the pair is the design’s.
Why the both’s remote’s matters. The both’s remote’s is the host’s-to-host’s, and the host’s-to-host’s is the transfer’s. The scp‘s is the both’s, and the both’s is the direct’s. The two are the pair, and the pair is the design’s.
Why the both’s remote’s is the local’s. The both’s remote’s is the local’s, and the local’s is the relay’s. The scp‘s is the local’s, and the local’s is the relay’s. The two are the pair, and the pair is the performance’s.
The copy’s the file’s. The scp file.txt user@example.com:/tmp/other.txt is the rename’s, and the rename’s is the destination’s.
scp file.txt user@example.com:/tmp/other.txt
The scp file.txt user@example.com:/tmp/other.txt is the rename’s, and the rename’s is the destination’s. The two are the pair, and the pair is the design’s.
Why the copy’s the file’s matters. The copy’s the file’s is the rename’s, and the rename’s is the destination’s. The scp file.txt user@host:/tmp/other.txt‘s is the rename’s, and the rename’s is the specified’s. The two are the pair, and the pair is the design’s.
The scp‘s options
The scp‘s options are the common’s, and the common’s is the control’s.
The -r‘s. The -r is the recursive’s, and the recursive’s is the directory’s.
scp -r project/ user@example.com:/tmp/
The scp -r project/ is the recursive’s, and the recursive’s is the directory’s. The two are the pair, and the pair is the design’s.
Why the -r matters. The -r is the recursive’s, and the recursive’s is the directory’s. The -r‘s is the tree’s, and the tree’s is the whole’s. The two are the pair, and the pair is the design’s.
The -P‘s. The -P is the port’s, and the port’s is the uppercase’s.
scp -P 2222 file.txt user@example.com:/tmp/
The scp -P 2222 is the port’s, and the port’s is the uppercase’s. The two are the pair, and the pair is the design’s.
Why the -P matters. The -P is the uppercase’s, and the uppercase’s is the scp‘s. The -p is the lowercase’s, and the lowercase’s is the preserve’s. The two are the pair, and the pair is the distinction’s.
The -i‘s. The -i is the key’s, and the key’s is the specific’s.
scp -i ~/.ssh/id_ed25519 file.txt user@example.com:/tmp/
The scp -i ~/.ssh/id_ed25519 is the key’s, and the key’s is the specific’s. The two are the pair, and the pair is the design’s.
Why the -i matters. The -i is the key’s, and the key’s is the multi-key’s. The -i‘s is the specific’s, and the specific’s is the choice’s. The two are the pair, and the pair is the design’s.
The -p‘s. The -p is the preserve’s, and the preserve’s is the timestamps’s and the modes’s.
scp -p file.txt user@example.com:/tmp/
The scp -p file.txt is the preserve’s, and the preserve’s is the timestamps’s. The two are the pair, and the pair is the design’s.
Why the -p matters. The -p is the preserve’s, and the preserve’s is the attributes’s. The -p‘s is the lowercase’s, and the lowercase’s is the preserve’s. The two are the pair, and the pair is the distinction’s.
The -C‘s. The -C is the compression’s, and the compression’s is the band’s.
scp -C file.txt user@example.com:/tmp/
The scp -C file.txt is the compression’s, and the compression’s is the band’s. The two are the pair, and the pair is the performance’s.
Why the -C matters. The -C is the compression’s, and the compression’s is the text’s. The -C‘s is the CPU’s, and the CPU’s is the tradeoff’s. The two are the pair, and the pair is the design’s.
The -q‘s. The -q is the quiet’s, and the quiet’s is the no-progress’s.
scp -q file.txt user@example.com:/tmp/
The scp -q file.txt is the quiet’s, and the quiet’s is the no-progress’s. The two are the pair, and the pair is the design’s.
Why the -q matters. The -q is the quiet’s, and the quiet’s is the script’s. The -q‘s is the no-output’s, and the no-output’s is the log’s. The two are the pair, and the pair is the design’s.
The -v‘s. The -v is the verbose’s, and the verbose’s is the debug’s.
scp -v file.txt user@example.com:/tmp/
The scp -v file.txt is the verbose’s, and the verbose’s is the debug’s. The two are the pair, and the pair is the diagnosis’s.
Why the -v matters. The -v is the verbose’s, and the verbose’s is the debug’s. The -v‘s is the diagnosis’s, and the diagnosis’s is the specific’s. The two are the pair, and the pair is the design’s.
The -l‘s. The -l is the bandwidth’s, and the bandwidth’s is the limit’s.
scp -l 1000 file.txt user@example.com:/tmp/
The scp -l 1000 is the bandwidth’s, and the bandwidth’s is the Kbit/s’s. The two are the pair, and the pair is the design’s.
Why the -l matters. The -l is the bandwidth’s, and the bandwidth’s is the limit’s. The -l‘s is the shared’s, and the shared’s is the courtesy’s. The two are the pair, and the pair is the design’s.
The -o‘s. The -o is the ssh’s option’s, and the option’s is the arbitrary’s.
scp -o StrictHostKeyChecking=no file.txt user@example.com:/tmp/
The scp -o StrictHostKeyChecking=no is the ssh’s option’s, and the option’s is the arbitrary’s. The two are the pair, and the pair is the design’s.
Why the -o matters. The -o is the ssh’s option’s, and the option’s is the arbitrary’s. The -o‘s is the specific’s, and the specific’s is the config’s. The two are the pair, and the pair is the design’s.
The scp‘s the SSH’s integration
The scp uses the SSH’s authentication, so the ~/.ssh/config‘s, the ssh-agent‘s, and the keys’s are the same’s.
The ~/.ssh/config‘s. The ~/.ssh/config is the alias’s, and the alias’s is the scp‘s.
Host example
HostName example.com
User alice
Port 2222
IdentityFile ~/.ssh/id_ed25519
The Host example is the alias’s, and the alias’s is the scp example:‘s. The two are the pair, and the pair is the design’s.
Why the ~/.ssh/config‘s matters. The ~/.ssh/config‘s is the alias’s, and the alias’s is the convenient’s. The scp file example:/tmp/ is the alias’s, and the alias’s is the full’s replacement’s. The two are the pair, and the pair is the design’s.
The ssh-agent‘s. The ssh-agent is the passphrase’s cache’s, and the cache’s is the scp‘s.
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
scp file.txt user@example.com:/tmp/
The ssh-agent‘s is the scp‘s, and the scp‘s is the passwordless’s. The two are the pair, and the pair is the design’s.
Why the ssh-agent‘s matters. The ssh-agent‘s is the passphrase’s, and the passphrase’s is the once’s. The scp‘s is the agent’s, and the agent’s is the convenient’s. The two are the pair, and the pair is the design’s.
The keys’s. The keys’s is the scp‘s, and the scp‘s is the key’s.
scp -i ~/.ssh/id_ed25519 file.txt user@example.com:/tmp/
The scp -i ~/.ssh/id_ed25519 is the keys’s, and the keys’s is the key’s. The two are the pair, and the pair is the design’s.
Why the keys’s matters. The keys’s is the scp‘s, and the scp‘s is the authentication’s. The keys’s is the SSH’s, and the SSH’s is the transport’s. The two are the pair, and the pair is the design’s.
The ControlMaster‘s. The ControlMaster‘s is the reuse’s, and the reuse’s is the scp‘s.
Host *
ControlMaster auto
ControlPath ~/.ssh/control-%r@%h:%p
ControlPersist 10m
The ControlMaster auto is the reuse’s, and the reuse’s is the scp‘s. The two are the pair, and the pair is the performance’s.
Why the ControlMaster‘s matters. The ControlMaster‘s is the reuse’s, and the reuse’s is the performance’s. The scp‘s is the reuse’s, and the reuse’s is the multi-file’s. The two are the pair, and the pair is the design’s.
Why the ControlMaster‘s is the scp‘s benefit. The ControlMaster‘s is the scp‘s benefit, and the benefit’s is the speed’s. The scp‘s is the reuse’s, and the reuse’s is the fast’s. The two are the pair, and the pair is the design’s.
The ProxyJump‘s. The ProxyJump is the bastion’s, and the bastion’s is the scp‘s.
scp -o ProxyJump=bastion file.txt user@internal:/tmp/
The scp -o ProxyJump=bastion is the bastion’s, and the bastion’s is the scp‘s. The two are the pair, and the pair is the design’s.
Why the ProxyJump‘s matters. The ProxyJump‘s is the bastion’s, and the bastion’s is the internal’s. The scp‘s is the bastion’s, and the bastion’s is the chain’s. The two are the pair, and the pair is the design’s.
The scp‘s the ~/.ssh/config‘s. The scp‘s the ~/.ssh/config‘s is the automatic’s, and the automatic’s is the seamless’s.
# ~/.ssh/config
Host internal
HostName 10.0.0.5
User alice
ProxyJump bastion
# The scp's:
scp file.txt internal:/tmp/
The scp file.txt internal:/tmp/ is the automatic’s, and the automatic’s is the seamless’s. The two are the pair, and the pair is the design’s.
Why the scp‘s the ~/.ssh/config‘s matters. The scp‘s the ~/.ssh/config‘s is the automatic’s, and the automatic’s is the seamless’s. The scp‘s is the config’s, and the config’s is the reuse’s. The two are the pair, and the pair is the design’s.
The scp‘s versus the rsync‘s
The scp is the simple’s, and the rsync‘s is the delta’s.
The scp‘s the whole’s. The scp‘s the whole’s is the file’s, and the file’s is the every’s.
scp file.txt user@example.com:/tmp/
# The whole's file's is the transferred's.
The scp file.txt is the whole’s, and the whole’s is the every’s. The two are the pair, and the pair is the design’s.
Why the scp‘s the whole’s matters. The scp‘s the whole’s is the file’s, and the file’s is the every’s. The scp‘s is the whole’s, and the whole’s is the simple’s. The two are the pair, and the pair is the design’s.
The rsync‘s the delta’s. The rsync‘s the delta’s is the changed’s, and the changed’s is the efficient’s.
rsync -avz file.txt user@example.com:/tmp/
# The changed's blocks's are the transferred's.
The rsync -avz file.txt is the delta’s, and the delta’s is the changed’s. The two are the pair, and the pair is the design’s.
Why the rsync‘s the delta’s matters. The rsync‘s the delta’s is the changed’s, and the changed’s is the efficient’s. The rsync‘s is the second’s, and the second’s is the fast’s. The two are the pair, and the pair is the design’s.
The scp‘s the simple’s. The scp‘s the simple’s is the first’s, and the first’s is the fast’s.
scp file.txt user@example.com:/tmp/
# The first's is the fast's.
The scp file.txt is the simple’s, and the simple’s is the first’s. The two are the pair, and the pair is the design’s.
Why the scp‘s the simple’s matters. The scp‘s the simple’s is the first’s, and the first’s is the fast’s. The scp‘s is the one-off’s, and the one-off’s is the simple’s. The two are the pair, and the pair is the design’s.
The rsync‘s the resume’s. The rsync‘s the resume’s is the --partial‘s, and the --partial‘s is the resume’s.
rsync -avz --partial file.txt user@example.com:/tmp/
The rsync -avz --partial is the resume’s, and the resume’s is the interrupted’s. The two are the pair, and the pair is the design’s.
Why the rsync‘s the resume’s matters. The rsync‘s the resume’s is the --partial‘s, and the --partial‘s is the large’s. The scp‘s is the restart’s, and the restart’s is the whole’s. The two are the pair, and the pair is the design’s.
The rsync‘s the exclude’s. The rsync‘s the exclude’s is the --exclude‘s, and the --exclude‘s is the pattern’s.
rsync -avz --exclude='*.log' project/ user@example.com:/tmp/project/
The rsync -avz --exclude='*.log' is the exclude’s, and the exclude’s is the pattern’s. The two are the pair, and the pair is the design’s.
Why the rsync‘s the exclude’s matters. The rsync‘s the exclude’s is the pattern’s, and the pattern’s is the selective’s. The scp‘s is the all’s, and the all’s is the whole’s. The two are the pair, and the pair is the design’s.
The scp‘s the security’s
The scp‘s the security’s is the SSH’s, and the SSH’s is the encrypted’s.
The scp‘s the SSH’s. The scp‘s the SSH’s is the transport’s, and the transport’s is the encrypted’s.
scp file.txt user@example.com:/tmp/
# The SSH's is the transport's.
The scp file.txt is the SSH’s, and the SSH’s is the encrypted’s. The two are the pair, and the pair is the security’s.
Why the scp‘s the SSH’s matters. The scp‘s the SSH’s is the transport’s, and the transport’s is the encrypted’s. The scp‘s is the secure’s, and the secure’s is the default’s. The two are the pair, and the pair is the design’s.
The scp‘s the host’s key’s. The scp‘s the host’s key’s is the known_hosts‘s, and the known_hosts‘s is the MITM’s.
scp file.txt user@example.com:/tmp/
# The known_hosts's is the check's.
The scp file.txt is the host’s key’s, and the host’s key’s is the known_hosts‘s. The two are the pair, and the pair is the security’s.
Why the scp‘s the host’s key’s matters. The scp‘s the host’s key’s is the known_hosts‘s, and the known_hosts‘s is the MITM’s. The scp‘s is the SSH’s, and the SSH’s is the same’s. The two are the pair, and the pair is the design’s.
The scp‘s the agent’s. The scp‘s the agent’s is the ssh-agent‘s, and the ssh-agent‘s is the passphrase’s.
scp file.txt user@example.com:/tmp/
# The ssh-agent's is the passphrase's.
The scp file.txt is the agent’s, and the agent’s is the passphrase’s. The two are the pair, and the pair is the security’s.
Why the scp‘s the agent’s matters. The scp‘s the agent’s is the ssh-agent‘s, and the ssh-agent‘s is the passphrase’s. The scp‘s is the agent’s, and the agent’s is the convenient’s. The two are the pair, and the pair is the design’s.
The scp‘s the -o‘s. The scp‘s the -o‘s is the option’s, and the option’s is the security’s.
scp -o StrictHostKeyChecking=yes file.txt user@example.com:/tmp/
The scp -o StrictHostKeyChecking=yes is the -o‘s, and the -o‘s is the option’s. The two are the pair, and the pair is the security’s.
Why the scp‘s the -o‘s matters. The scp‘s the -o‘s is the option’s, and the option’s is the security’s. The scp‘s is the SSH’s, and the SSH’s is the same’s. The two are the pair, and the pair is the design’s.
The scp‘s the -i‘s. The scp‘s the -i‘s is the key’s, and the key’s is the authentication’s.
scp -i ~/.ssh/id_ed25519 file.txt user@example.com:/tmp/
The scp -i ~/.ssh/id_ed25519 is the -i‘s, and the -i‘s is the key’s. The two are the pair, and the pair is the authentication’s.
Why the scp‘s the -i‘s matters. The scp‘s the -i‘s is the key’s, and the key’s is the authentication’s. The scp‘s is the SSH’s, and the SSH’s is the same’s. The two are the pair, and the pair is the design’s.
Complete Example Session
# ============================================
# PART 1: THE BASIC UPLOAD
# ============================================
scp file.txt user@example.com:/tmp/
# file.txt 100% 1024 1.2MB/s 00:00
# ============================================
# PART 2: THE BASIC DOWNLOAD
# ============================================
scp user@example.com:/tmp/file.txt .
# file.txt 100% 1024 1.2MB/s 00:00
# ============================================
# PART 3: THE RECURSIVE
# ============================================
scp -r project/ user@example.com:/tmp/
# project/index.js 100% 2048 2.0MB/s 00:00
# project/utils.js 100% 1024 1.0MB/s 00:00
# ============================================
# PART 4: THE PORT
# ============================================
scp -P 2222 file.txt user@example.com:/tmp/
# ============================================
# PART 5: THE KEY
# ============================================
scp -i ~/.ssh/id_ed25519 file.txt user@example.com:/tmp/
# ============================================
# PART 6: THE PRESERVE
# ============================================
scp -p file.txt user@example.com:/tmp/
# The timestamps's and the modes's are the preserved's.
# ============================================
# PART 7: THE COMPRESSION
# ============================================
scp -C file.txt user@example.com:/tmp/
# The text's is the compressed's.
# ============================================
# PART 8: THE SSH CONFIG
# ============================================
# ~/.ssh/config
# Host example
# HostName example.com
# User alice
# Port 2222
# IdentityFile ~/.ssh/id_ed25519
scp file.txt example:/tmp/
# The alias's is the used's.
# ============================================
# PART 9: THE SSH AGENT
# ============================================
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
scp file.txt user@example.com:/tmp/
# The passphrase's is the cached's.
# ============================================
# PART 10: WHAT NOT TO DO
# ============================================
# Don't use the -p on the scp for the port
scp -p 2222 file.txt user@example.com:/tmp/ # โ the -p is the preserve'sโ# โ ๏ธ
# Don't forget the -r for the directory
scp project/ user@example.com:/tmp/ # โ the directory's // โ ๏ธ
# Don't use the scp for the large's and the repeated's
# The rsync's is the delta's. // โ ๏ธ
# Don't forget the colon's
scp file.txt user@example.com /tmp/ # โ the two arguments's // โ ๏ธ
# Don't use the scp for the sensitive's without the encryption's
# The scp's is the SSH's, so the encryption's is the default's.โ# โ ๏ธ
# Don't forget the host's key's
scp -o StrictHostKeyChecking=no file.txt user@example.com:/tmp/โ# โ ๏ธ
The ten parts cover the basic upload, the basic download, the recursive, the port, the key, the preserve, the compression, the SSH config, the SSH agent, and the anti-patterns.
Quick Reference
The scp‘s Syntax
| Form | Purpose |
|---|---|
scp file user@host:/path | The upload’s |
scp user@host:/path file | The download’s |
scp user1@host1:/p user2@host2:/p | The both’s |
scp file user@host:/path/new | The rename’s |
The scp‘s Options
| Option | Purpose |
|---|---|
-r | The recursive’s |
-P PORT | The port’s (the uppercase’s) |
-i KEY | The key’s |
-p | The preserve’s (the lowercase’s) |
-C | The compression’s |
-q | The quiet’s |
-v | The verbose’s |
-l KBIT | The bandwidth’s |
-o OPT | The ssh’s option’s |
The Remote’s Syntax
| Form | Purpose |
|---|---|
host:path | The host’s and the path’s |
user@host:path | The user’s |
host:path with the space's | The quote’s |
The scp‘s vs the rsync‘s
| Aspect | scp | rsync |
|---|---|---|
| The transfer’s | The whole’s | The delta’s |
| The resume’s | No | Yes (--partial) |
| The exclude’s | No | Yes (--exclude) |
| The speed’s | The simple’s | The fast’s |
| The use’s | The one-off’s | The repeated’s |
The SSH’s Integration
| Feature | Purpose |
|---|---|
The ~/.ssh/config | The alias’s |
The ssh-agent | The passphrase’s |
The -i | The key’s |
The ControlMaster | The reuse’s |
The ProxyJump | The bastion’s |
Best Practices
โ Do This:
# Use the basic upload
scp file.txt user@example.com:/tmp/ # โ
# Use the recursive for the directory
scp -r project/ user@example.com:/tmp/ # โ
# Use the -P (the uppercase's) for the port
scp -P 2222 file.txt user@example.com:/tmp/ # โ
# Use the -i for the specific's key
scp -i ~/.ssh/id_ed25519 file.txt user@example.com:/tmp/ # โ
# Use the ~/.ssh/config for the alias
scp file.txt example:/tmp/ # โ
# Use the ssh-agent for the passphrase
eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519 # โ
# Use the rsync for the large's and the repeated's
rsync -avz project/ user@example.com:/tmp/project/ # โ
โ Don’t Do This:
# Don't use the -p for the port
scp -p 2222 file.txt user@example.com:/tmp/ # โ the preserve's // โ ๏ธ
# Don't forget the -r for the directory
scp project/ user@example.com:/tmp/ # โ the directory's // โ ๏ธ
# Don't forget the colon's
scp file.txt user@example.com /tmp/ # โ the two arguments's // โ ๏ธ
# Don't use the scp for the repeated's
scp -r project/ user@example.com:/tmp/ # the rsync's is the better'sโ# โ ๏ธ
# Don't use the StrictHostKeyChecking=no
scp -o StrictHostKeyChecking=no file.txt user@example.com:/tmp/โ# โ ๏ธ
# Don't forget the space's quote's
scp my file.txt user@example.com:/tmp/ # โ the two files's // โ ๏ธ
Common Pitfalls
| Pitfall | Problem | Solution |
|---|---|---|
The -p for the port | The preserve’s | The -P |
The missing -r | The directory’s error | The -r |
| The missing colon | The two arguments’s | The host:path |
| The space’s quote’s | The split | The "my file.txt" |
The StrictHostKeyChecking=no | The MITM’s | The yes’s |
| The scp for the repeated’s | The whole’s | The rsync |
| The scp for the resume’s | The restart’s | The rsync --partial |
The missing ~/.ssh/config | The verbose’s | The config’s |
Real-World Examples
1. The basic upload
scp file.txt user@example.com:/tmp/
2. The basic download
scp user@example.com:/tmp/file.txt .
3. The recursive
scp -r project/ user@example.com:/tmp/
4. The port
scp -P 2222 file.txt user@example.com:/tmp/
5. The key
scp -i ~/.ssh/id_ed25519 file.txt user@example.com:/tmp/
6. The preserve
scp -p file.txt user@example.com:/tmp/
7. The compression
scp -C file.txt user@example.com:/tmp/
8. The alias
scp file.txt example:/tmp/
9. The SSH agent
eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_ed25519 && scp file.txt user@example.com:/tmp/
10. The rename
scp file.txt user@example.com:/tmp/other.txt
Visual: The scp‘s Syntax
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ scp [options] source destination โ
โ โ โ
โ โโโ -r the recursive's โ
โ โโโ -P PORT the port's (the uppercase's) โ
โ โโโ -i KEY the key's โ
โ โโโ -p the preserve's โ
โ โโโ -C the compression's โ
โ โโโ -q the quiet's โ
โ โโโ -v the verbose's โ
โ โโโ -l KBIT the bandwidth's โ
โ โโโ -o OPT the ssh's option's โ
โ โ
โ THE REMOTE'S: [user@]host:path โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Visual: The scp‘s Flow
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ THE LOCAL โ
โ file.txt โ
โ โ โ
โ โ scp file.txt user@host:/tmp/ โ
โ โผ โ
โ THE SSH'S CONNECTION โ
โ (the encrypted's) โ
โ โ โ
โ โผ โ
โ THE REMOTE'S โ
โ /tmp/file.txt โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Visual: The scp‘s vs the rsync‘s
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ THE SCP'S โ
โ The whole's file's is the transferred's. โ
โ The repeat's is the whole's again's. โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ THE RSYNC'S โ
โ The changed's blocks's are the transferred's.โ
โ The repeat's is the delta's. โ
โ The resume's is the `--partial`'s. โ
โ The exclude's is the `--exclude`'s. โ
โ โ
โ The scp's is the simple's, and the rsync's โ
โ is the efficient's. โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Visual: The scp‘s the SSH’s Integration
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ THE SSH'S FEATURES โ
โ โ โ
โ โโโ ~/.ssh/config โ
โ โ The alias's, the port's, the key's โ
โ โ โ
โ โโโ ssh-agent โ
โ โ The passphrase's cache's โ
โ โ โ
โ โโโ ControlMaster โ
โ โ The connection's reuse's โ
โ โ โ
โ โโโ ProxyJump โ
โ The bastion's โ
โ โ
โ The scp's uses the same's. โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Visual: The scp‘s Options’s the -p vs the -P
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ THE -p (the lowercase's) โ
โ The preserve's โ
โ The timestamps's and the modes's โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ THE -P (the uppercase's) โ
โ The port's โ
โ The non-default's SSH's port's โ
โ โ
โ The case's is the distinction's. โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Summary
| Item | Value |
|---|---|
| The basic | scp file user@host:/path |
| The download | scp user@host:/path file |
| The recursive | -r |
| The port | -P (the uppercase’s) |
| The key | -i |
| The preserve | -p (the lowercase’s) |
| The compression | -C |
| The quiet | -q |
| The verbose | -v |
| The SSH’s integration | The config’s, the agent’s, the keys’s |
| The vs the rsync’s | The simple’s vs the delta’s |
Key takeaways:
- The
scp source destinationis the basic’s, and the remote’s is the[user@]host:path‘s โ the colon is the distinction’s between the local’s and the remote’s - The
-ris the recursive’s, and the directory’s requires it โ thescp -r project/ user@host:/tmp/is the pattern’s - The
-P(the uppercase’s) is the port’s, and the-p(the lowercase’s) is the preserve’s โ the case’s is the distinction’s, and the confusion is the common’s - The
-iis the key’s, and the~/.ssh/config‘s is the alias’s โ the two are the SSH’s, and thescpuses the same’s - The
ssh-agent‘s is the passphrase’s cache’s โ thescp‘s is the agent’s, and the passwordless’s is the convenient’s - The
scp‘s is the whole’s file’s, and thersync‘s is the delta’s โ thescpis the simple’s and the one-off’s, and thersyncis the efficient’s and the repeated’s - The
scp‘s is the SSH’s transport’s, and the encryption’s is the default’s โ theknown_hosts‘s is the MITM’s prevention’s - The
scp‘s is the ubiquitous’s, and the OpenSSH 9.0’s is the deprecation’s โ thesftp‘s and thersync‘s are the modern’s, but thescp‘s is the compatible’s - The
ControlMaster‘s is the reuse’s, and thescp‘s is the multi-file’s benefit’s โ the reuse’s is the performance’s - The
ProxyJump‘s is the bastion’s, and thescp‘s is the internal’s โ the-o ProxyJump=bastion‘s is the pattern’s
Remember: The scp‘s is the cp‘s remote’s version, and the remote’s is the SSH’s transport’s. The -r‘s is the recursive’s, and the -P‘s is the port’s, and the -p‘s is the preserve’s. The ~/.ssh/config‘s is the alias’s, and the ssh-agent‘s is the passphrase’s. The scp‘s is the simple’s, and the rsync‘s is the efficient’s. The scp‘s is the ubiquitous’s, and the ubiquitous’s is the compatible’s.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!