Skip to content
Latchkey

scp: Usage, Options & Common CI Errors

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

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

What it does

scp securely copies files and directories between the local machine and a remote host (or between two remotes) using the SSH protocol for transport and authentication.

Common usage

Terminal
scp -i key.pem app.tar.gz user@host:/srv/app/
scp -r ./dist user@host:/var/www/
scp -P 2222 file user@host:/tmp/        # note: uppercase -P for port
scp user@host:/var/log/app.log ./

Options

FlagWhat it does
-rRecursively copy directories
-i <file>Identity (private key) file
-P <port>Remote port (uppercase, unlike ssh -p)
-pPreserve modification times and modes
-CEnable compression

Common errors in CI

Host key verification failed - same fix as ssh: seed known_hosts. "scp: /path: Permission denied" means the remote user cannot write the target dir. "not a regular file" appears when copying a directory without -r. A classic trip-up: scp uses -P for the port while ssh uses lowercase -p. Newer OpenSSH may warn scp is using the legacy protocol; rsync or sftp is the modern alternative.

Related guides

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