Skip to content
Latchkey

scp: Copy Files Over SSH in Pipelines

scp copies files and directories between hosts over an SSH connection.

After a build, scp is the simplest way to push artifacts to a deploy host or pull logs back. It reuses ssh's auth and host key checks, so the same setup applies.

What it does

scp transfers files over SSH. The remote side is written as user@host:path; either source or destination can be remote. It authenticates and verifies host keys exactly like ssh, reading the same keys, known_hosts, and ~/.ssh/config.

Common usage

Terminal
# upload a build artifact to the server
scp ./dist/app.tar.gz user@host:/srv/app/
# download a log back to the runner
scp user@host:/var/log/app.log ./app.log
# use a specific key and the same host alias from ssh config
scp -i deploy_key ./app.tar.gz prod:/srv/app/

Options

FlagWhat it does
-i <key>Identity file (same as ssh -i)
-rRecursively copy a directory
-P <port>Remote port (uppercase!)
-CCompress data in transit
-pPreserve modification times and modes
-qQuiet; suppress the progress meter

In CI

scp uses the same known_hosts and StrictHostKeyChecking as ssh, so seed the host key with ssh-keyscan first. Pass -o options just like ssh: scp -o StrictHostKeyChecking=accept-new file host:path. Keep the deploy key at mode 600 or scp skips it.

Common errors in CI

Host key verification failed. means the host is not in known_hosts; run ssh-keyscan first. "scp: /srv/app/: Permission denied" is a remote filesystem permission, not an SSH one; check the deploy user's rights. "not a regular file" without -r means you tried to copy a directory; add -r.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →