Skip to content
Latchkey

scp Command Reference for CI Scripts

scp copies files to or from a remote host over an SSH connection.

scp is the quick way to move an artifact to a server in a deploy step. It inherits all of SSH\u2019s host-key and key-permission requirements, plus a few of its own quirks.

Common flags/usage

  • -r: recursively copy directories
  • -i FILE: identity (private key) file
  • -P PORT: remote port (uppercase, unlike ssh -p)
  • -p: preserve modification times and modes
  • -C: enable compression

Example

shell
scp -i "${HOME}/.ssh/id_ed25519" -o BatchMode=yes \
  "release-${VERSION}.tar.gz" "deploy@${HOST}:/srv/app/"

In CI

scp uses uppercase -P for the port while ssh uses lowercase -p, a classic trip-up. "Host key verification failed" has the same fix as ssh: seed known_hosts with ssh-keyscan. "not a regular file" appears when copying a directory without -r. For repeated deploys, rsync transfers only the changes.

Key takeaways

  • scp uses uppercase -P for the port, opposite to ssh\u2019s -p.
  • Seed known_hosts first or scp fails on host-key verification.
  • Use -r for directories; rsync is better for repeated deploys.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →