Network and remote access

Command scp

Copy files over SSH

Linux · Bash examples · commands run on the selected server

When to use scp

Use scp for a simple file copy between SSH-accessible systems. Direction depends on which argument contains the remote account and host; verify the destination path to avoid writing to an unexpected home directory.

Syntax

scp [PARAMETERS] SOURCE DESTINATION

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

-P PORT
SSH port; scp uses an uppercase P.
-i KEY
Path to the private SSH key.
-r
Recursively copy a directory.

Usage examples

Upload file to server

scp ./report.txt deploy@server.example.com:/srv/app/

A local report is uploaded into an existing directory on the remote server.

Download file

scp deploy@server.example.com:/srv/app/report.txt ./report.txt

A remote report is downloaded to the specified local filename.

Use a different port

scp -P 2222 ./report.txt deploy@server.example.com:/srv/app/

The upload uses a nondefault SSH port, expressed with the uppercase port option.

Notes and limitations

  • In modern OpenSSH scp usually uses SFTP; older versions and -O use legacy SCP.
  • Check the server key and destination path: existing files may be overwritten.

Common questions and troubleshooting

Why does lowercase -p not select a port?

For scp it preserves selected attributes; the port flag is uppercase -P. This differs from the SSH client's lowercase port flag.

Why does copying fail although SSH login works?

The destination may be unwritable or the required file-transfer subsystem unavailable. Modern OpenSSH scp commonly uses SFTP by default, so check server support.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man scp.