Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
Step by step
- One file or a few files → scp:
scp -P 2222 app.jar deploy@192.0.2.20:/opt/app/
scp -J bastion db-dump.sql.gz admin@10.0.1.21:/backup/
scp -p report.pdf web2:/srv/reports/-P port (capital P), -J through a jump host, -p keep times and modes.
- Folders, big files, repeated syncs → rsync:
rsync -avzP ./site/ web2:/srv/site/
rsync -avzP -e 'ssh -p 2222' ./site/ deploy@192.0.2.20:/srv/site/
rsync -avzP --exclude='.git' --exclude='node_modules' ./ web2:/srv/app/
rsync -aHAX --numeric-ids /srv/data/ backup1:/backup/data/| Option | Meaning |
|---|---|
-a | Archive: folders, links, times, modes, owners (as root). |
-v / -z | Show files / compress on the way. |
-P | Show progress and keep partial files (resume a broken copy). |
--delete | Delete files on the target that are gone in the source (a real mirror). |
-n / --dry-run | Show what would happen, change nothing. |
-HAX | Keep hard links, ACLs and extended attributes (system data). |
Onthoud
the trailing slash matters. ./site/ = the contents of site; ./site = the folder site itself (you get /srv/site/site).
- **Always dry-run before
--delete:**
- Server to server (your laptop in the middle, no keys between the servers):
scp -3 web1:/backup/shop.tar.gz web2:/backup/Or log in to web1 and push to web2 directly (faster, needs SSH access from web1 to web2).
- Interactive browsing (look first, then get files):
sftp web2
sftp> cd /var/log/nginx
sftp> get access.log
sftp> byeCheck that it worked
Compare checksums on both sides — size alone is not proof:
The two hashes must be the same. rsync -avnc (checksum dry-run) lists no files when both sides are equal.
Common problems
| Problem | Cause | Fix |
|---|---|---|
Permission denied (publickey) | Key not on the target, or wrong user. | ssh web2 first; fix the key login (ssh-copy-id). |
Permission denied on the target path | No write right in that folder. | Copy to /tmp or your home, then sudo mv; or fix the owner. |
You get /srv/site/site | No trailing slash on the source. | Use ./site/ (with slash) to copy the contents. |
| A big copy broke in the middle | Network cut. | Run the same rsync -P again — it resumes. |
rsync: command not found | rsync must be installed on both sides. | dnf install rsync / apt install rsync on the target too. |
| Old scp script fails with "protocol" errors | Since OpenSSH 9, scp uses the SFTP protocol. | Use scp -O (old protocol) for very old servers, or switch to rsync. |
Go further
- Command pages: scp, rsync, sftp, ssh.
- Next how-tos: Log in with SSH keys, Create and extract tar.gz archives, Schedule a job with cron, Sync folders with rsync.
- Learn it: RH134 — rsync, RH134 — The trailing slash, RHCSA — scp, TLCL — rsync over the network.
- Full guide: Install and harden the OpenSSH server. At work: rsync in daily DevOps.
- Practise: Lab: copy, sync and reboot safely.
1Why is rsync better than scp for a 20 GB folder?
It sends only changed files, can resume a broken copy (-P), and can mirror with --delete.
2What is the difference between rsync ./site/ host:/srv/site/ and rsync ./site host:/srv/site/?
With the slash, the contents of site are copied; without it, the folder itself (you get /srv/site/site).