Introduction
SCP (Secure Copy Protocol) is a powerful command for securely copying files and folders between local and remote machines via SSH. Unlike FTP, SCP encrypts data in transit to prevent interceptions. It's ideal for developers, sysadmins, and system administration beginners, simplifying deployments without complex tools.
Why use it in 2026? With rising cyber threats, SCP remains a reliable standard, natively integrated into Linux/macOS and available on Windows via OpenSSH. This beginner tutorial progresses from basics (simple copies) to advanced cases (folders, custom ports), with 100% functional examples. By the end, you'll transfer any file in 2 minutes like a pro. (128 words)
Prerequisites
- Linux/macOS system or Windows with OpenSSH installed (via Settings > Apps > Optional features).
- SSH access to a remote machine (IP, username, password, or SSH key).
- Basic terminal knowledge (cd, ls).
- Test SSH first:
ssh user@ip.
Copy a local file to remote
scp /chemin/vers/fichier-local.txt utilisateur@192.168.1.100:/dossier/distant/This command copies fichier-local.txt from your local machine to /dossier/distant/ on the remote machine. Replace utilisateur with your username, 192.168.1.100 with the real IP, and paths with your own. It prompts for the SSH password if no key is set up.
Verify the transfer
After running the command, connect via SSH (ssh utilisateur@192.168.1.100) and list the remote directory (ls /dossier/distant/) to confirm. SCP shows progress (size, speed), giving you a visual gauge of the transfer.
Copy a folder recursively
scp -r /chemin/vers/dossier-local/ utilisateur@192.168.1.100:/dossier/distant/The -r (recursive) option copies the entire folder and its nested contents. Great for full projects. Note: paths end with / to copy the contents of the folder, not the folder itself.
From remote to local
Reverse the flow by swapping source and destination. Perfect for pulling backups or logs.
Copy a remote file to local
scp utilisateur@192.168.1.100:/dossier/distant/fichier-distant.txt /chemin/local/Here, the remote file lands on your local machine. The order is reversed from step 1. SCP handles the incoming SSH connection automatically.
Copy a remote folder to local
scp -r utilisateur@192.168.1.100:/dossier/distant/ /chemin/local/With -r, the entire remote folder is copied locally. Check disk space first to avoid failures.
Use an SSH key (passwordless)
Generate a key with ssh-keygen (hit Enter for defaults), then copy it: ssh-copy-id utilisateur@192.168.1.100. SCP now runs seamlessly without passwords.
SCP with a non-standard port
scp -P 2222 /chemin/local/fichier.txt utilisateur@192.168.1.100:/dossier/distant/The -P 2222 option (uppercase!) targets a custom SSH port (default 22). Essential for secured servers. Note the uppercase to avoid confusion with -p (preserve permissions).
Limit bandwidth
scp -l 1000 /chemin/local/gros-fichier.zip utilisateur@192.168.1.100:/dossier/distant/-l 1000 limits to 1000 Kbit/s (1 Mbit/s), preventing connection saturation. Adjust based on your bandwidth for stable transfers.
Best practices
- Always use SSH keys: Avoids plaintext passwords and enables automation.
- End folders with
/: Copies contents, not the wrapper. - Check permissions:
scp -ppreserves timestamps/permissions (scp -p fichier user@host:/dest/). - Test small first: Copy a single file before a massive folder.
- Logs: Add
-v(verbose) for debugging (scp -v ...).
Common errors to avoid
- Port confusion:
-p(lowercase) preserves metadata, not port;-P(uppercase) for port. - Forgot absolute paths: Use
/home/user/instead of~, as SCP doesn't always expand it. - Disk space:
scpdoesn't check; monitor withdf -h. - SSH firewall: Test
sshfirst, or get "Connection refused".
Next steps
Explore rsync for incremental syncs (rsync -avz), or sftp for interactive use. Official docs: man scp.
Check out our Learni Linux administration courses to master SSH, Docker, and more.