scp

Securely copy files between hosts over SSH.

Synopsis

scp [options] source target

When to Use It

Use scp for quick one-off file transfers between your machine and a server, shipping logs off a host, copying deployment bundles to a VM, or moving files through an SSH bastion without setting up a larger sync workflow.

Core Options

-P PORT

Connect to a custom port.

-i file

Use a specific private key.

-r

Copy directories recursively.

-C

Enable compression.

-J host

ProxyJump via a bastion host.

Usage Examples

Copy to Server

Upload a file.

scp file.txt user@server:/opt/data/

Copy from Server

Download a file.

scp user@server:/opt/data/report.csv .

Copy Directory

Upload a folder recursively.

scp -r ./logs user@server:/var/tmp/

Custom Port & Key

Use a key and non-default port.

scp -i ~/.ssh/id_ed25519 -P 2222 file.txt user@server:/opt/data/

Via Bastion Host

Copy through a jump server.

scp -J bastion.example.com ./build.tar.gz user@app:/srv/releases/

Remote to Remote

Copy between two remote hosts when your machine is only the control point.

scp user@source:/var/log/app.log user@target:/tmp/app.log

Common Mistakes

  • scp overwrites target files without much ceremony, so double-check the destination path before pressing Enter.
  • Custom SSH ports use uppercase -P, while lowercase -p preserves timestamps in some implementations. Mixing them up is common.
  • For frequent or large sync jobs, rsync over SSH is usually safer and faster because it can resume and copy only changed blocks.

Related

Built for builders.