Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

scp

Copy files between systems over SSH (secure copy).

Niveau
RHCSA-examen
Groep
SSH en werken op afstand
Root nodig
Nee
Pakket
openssh-clients

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

scp works like cp, but one side (or both) can be on another system: user@host:path. All data is encrypted by SSH, and it uses the same login (password or key) as ssh.

New OpenSSH versions (also on RHEL 9 and 10) use the SFTP protocol under the hood by default; the command stays the same. For big or repeated copies, rsync is better: it copies only what changed.

Zo schrijf je het

scp [OPTIONS] SOURCE... TARGET
scp [OPTIONS] [USER@]HOST:PATH LOCAL_PATH
scp [OPTIONS] LOCAL_PATH [USER@]HOST:PATH

Opties 22

Meest gebruikt

-r
Copy folders with all their content.
-P port
The SSH port of the remote host (capital P!).
-p
Keep modification times, access times and permissions.
-i file
Use this private key.
-J destination
Copy through a jump host.
-C
Compress the data (helps on slow links).
-l limit
Limit the bandwidth in Kbit/s.
-q
Quiet: no progress meter.
-v
Verbose debug output.
-3
Copy between two remote hosts through your computer.
-R
Copy between two remote hosts directly (the source host connects to the target).
-B
Batch mode: never ask for a password (fail instead).
-o option
Pass an ssh option, like -o StrictHostKeyChecking=accept-new.
-F file
Use another ssh client config file.
-c cipher
Choose the cipher.
-S program
Use this program instead of ssh for the connection.
-4 / -6
Use only IPv4 / only IPv6.
-A
Forward the ssh-agent.
-O
Use the old SCP protocol instead of SFTP (for old servers).
-D path
The sftp-server program to use (with SFTP mode, for testing).
-X sftp-option
Options for the SFTP protocol (like buffer size).
-T
Turn off the strict file name checks of the old protocol.

Voorbeelden 12

$ als gewone gebruiker# als root (of met sudo)

  1. 1Copy a file to a server

    scp report.pdf student@server2:/tmp/

    The file keeps its name in /tmp on server2.

  2. 2Copy a file from a server

    scp student@server2:/var/log/dnf.log ./server2-dnf.log

    The remote side comes first now.

  3. 3Copy a folder

    scp -r ~/website student@server2:/var/www/

    -r for folders.

  4. 4Use another SSH port

    scp -P 2222 backup.tar.gz admin@backup01:/srv/backups/

    Capital P in scp (small p in ssh).

  5. 5Keep times and permissions

    scp -p config.yaml server2:/etc/myapp/

    The copy has the same time stamps.

  6. 6Copy through a bastion host

    scp -J admin@bastion.example.com app.jar admin@10.10.0.15:/opt/app/

    One command, even when the target is in a private network.

  7. 7Copy between two remote servers

    scp -3 server1:/srv/data.sql server2:/srv/

    Data goes through your computer; the servers do not need keys for each other.

  8. 8Limit the bandwidth

    scp -l 8000 big.iso server2:/tmp/

    About 1 MB/s, so the copy does not fill the office link.

  9. 9Use a deploy key in a pipeline

    scp -i ~/.ssh/ci_deploy -o StrictHostKeyChecking=accept-new dist.tar.gz deploy@web01:/srv/releases/

    Typical step in a CI job.

  10. 10Copy many files with a wildcard on the remote side

    scp 'server2:/var/log/httpd/*.log' ./logs/

    Quotes stop your local shell from expanding the *.

  11. 11Copy a file with spaces in the name

    scp "server2:/srv/share/Q3 report.xlsx" .

    Quote the remote path.

  12. 12Batch mode in a script

    scp -B -q backup.tgz backup@nas:/backups/ || echo "copy failed"

    Never hangs on a password prompt.

Let op

  • scp file host: (with nothing after the colon) copies to the home folder; scp file host (no colon) makes a local copy named "host".
  • scp overwrites existing target files without asking.
  • For large trees or repeated copies use rsync (it can resume and skips unchanged files).

Tips om te onthouden

  • Remote = user@host:path. -r folders, -P port, -p keep times.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man scp