Copying files with SCP
Complete guide to using Secure Copy in Linux.
SCP (Secure Copy) is a fast, secure command-line tool for transferring files and directories between your local machine and a remote server — or even between two remote servers — over an encrypted SSH connection. It's perfect for moving backups, website files, databases, or configs on your VPS or dedicated server.
SCP uses the same authentication as SSH: password or (much better) SSH keys.
Basic syntax
scp [options] source destination
- source — what you're copying (file or folder)
- destination — where to put it
Either source or destination can be:
- Local path:
/home/user/backup.zip - Remote path:
user@server-ip:/path/to/destination/
Most useful SCP options
-r— recursive (copy directories and all contents)-Pport — specify non-standard SSH port (e.g., -P 2222)-p— preserve modification times, permissions, and ownership-v— verbose mode (shows detailed progress and errors)-C— enable compression (speeds up transfer on slow connections)-ikeyfile — use specific private SSH key-llimit — limit bandwidth (in Kbit/s), e.g.,-l 800= ~100 KB/s
Practical examples
- Download a single file from server to local machine
scp user@192.168.1.100:/var/www/site.ru/wp-config.php ~/Downloads/
- ** file from server to local machine**
scp -r user@192.168.1.100:/var/www/site.ru/uploads ~/backup/
- Upload a folder from local to server
scp -r ./public_html user@192.168.1.100:/home/user/
- Copy between two remote servers
scp -r user1@server1.example.com:/var/www/site user2@server2.example.com:/backup/
- Use non-standard SSH port
scp -P 2222 important.sql user@server-ip:/home/user/
- Use a specific SSH private key
scp -i ~/.ssh/my_special_key backup.tar.gz user@server-ip:/home/user/
Quick tips for everyday use
- Always add
-rwhen copying directories — otherwise subfolders are ignored - Use
-vwhen troubleshooting — it shows exactly where things go wrong - For large transfers or slow connections — add
-Cto enable compression - For resuming interrupted transfers or syncing only changes — switch to rsync (much smarter than SCP)
- Prefer SSH keys over passwords for automation — they're far more secure and convenient
- SCP requires a working SSH connection — if SSH fails, SCP will too
Common real-world tasks
- Download full website files (public_html):
scp -r user@your-server:/home/user/public_html ~/local-backup/
- Upload full website to server:
scp -r ./public_html user@your-server:/home/user/
- Transfer a database dump:
scp mydb.sql user@your-server:/home/user/
Help
If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!