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
ssh Command Reference for CI Scriptsssh opens a secure remote shell or runs a remote command in CI deploys. Reference for -i, -o, BatchMode, and…
rsync Command Reference for CI Scriptsrsync synchronizes files efficiently in CI deploys and cache restores. Reference for -a, -z, --delete, and th…
ssh-keyscan Command Reference for CI Scriptsssh-keyscan fetches a host\u2019s public keys to pre-seed known_hosts in CI. Reference for -H, -t, -p, and th…
tar Command Reference for CI Scriptstar bundles and extracts archives in CI for caches and artifacts. Reference for -c, -x, -z, -C, and the compr…