Copy files over SSH with scp

Push or pull files and whole directories between machines using cp-like syntax over an encrypted SSH channel.

LinuxsshtransferscpLow risk
Run `scp -r ./build user@server:/var/www/app` to copy a directory to a remote host, or swap the arguments to copy back.

01Command

Command
$ scp -r ./build user@server:/var/www/app

02What it does

scp reads exactly like cp: the source(s) first, the destination last, with remote paths written as `user@host:/path`. `-r` recurses into directories, and `-P 2222` (capital P, unlike ssh's lowercase) handles nonstandard ports. To pull instead of push, just reverse the operands: `scp user@server:/var/log/app.log ./`. For resumable or delta transfers over the same channel, rsync is the better tool, but for a one-off file scp is already there.

03Risk

RiskLow risk
Requirementsopenssh-clients; SSH access to the remote host
!Warning: scp overwrites destination files silently — double-check the destination path, and note the port flag is capital `-P`, not ssh's lowercase `-p`.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • scp(1) — OpenSSH secure file copy
    Ubuntu manpages · technical · 2026-09-17
    Evidence: Documents scp copy semantics, -r for directories, -P for nonstandard remote port, and remote path syntax.

Last verified: 2026-09-17 · Category: Network