Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · sockets & transfer

scp

copy files over SSH

scp is cp across the network. A remote path is written user@host:path, and the copy travels inside an SSH connection, so it is encrypted and uses the same keys and passwords as ssh.

The colon is what makes it remote: host:path. Without one, scp copies locally.

Upload
scp file user@host:path
local to remote
Download
scp user@host:path .
remote to local
Directories
-r
recursive
Port
-P
capital, unlike ssh

At the terminal

Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.

user@netflow — bashopenssh-client
$ scp site-backup.tar.gz deploy@192.0.2.10:/tmp/
1site-backup.tar.gz 100% 1215KB 4.1MB/s 00:00
2$ scp deploy@192.0.2.10:/var/log/app/app.log .
app.log 100% 21KB 310.2KB/s 00:00
3$ scp -r site/ deploy@192.0.2.10:/var/www/
index.html 100% 4210 128.4KB/s 00:00
style.css 100% 1822 61.0KB/s 00:00
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
An upload

The local file goes to /tmp on the server. The line shows the name, percentage, size, speed and time.

2
A download

The remote path comes first and the destination is the dot: the current directory.

3
A whole directory

-r copies site and everything in it, printing a line for each file.

Switches

A switch changes how the command behaves. These are the ones used day to day; man scp lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.

-r
Recursive: copy directories.
-P PORT
Connect to this port. Capital P.
-p
Preserve modification times and modes.
-i FILE
Use this private key.
-C
Compress data in transit.
-q
Quiet: no progress meter.

Variations worth knowing

The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.

scp -P 2222 file deploy@192.0.2.10:

Uses another port. A bare colon means the remote home directory.

scp -p file deploy@192.0.2.10:/tmp/

Preserves the file’s modification time and mode.

scp host1:/tmp/a.txt host2:/tmp/

Copies from one remote machine to another.

rsync -avhP site/ deploy@192.0.2.10:/var/www/site/

Better for large or repeated copies: resumes, and sends only changes.

In cybersecurity

scp is the encrypted replacement for FTP and rcp.

Never FTP a secret

FTP sends the password and the file in clear text. scp, sftp and rsync over SSH protect both.

Mind where files land

A file uploaded to /tmp is readable by other users on the server unless its mode says otherwise. Copy secrets straight to a private directory.

It overwrites without asking

scp replaces an existing file of the same name silently. Check the destination path, especially with -r.

Protocols it shows

SSHSFTPTCP

Read alongside