SCP examples

Last updated:

WIP Alert This is a work in progress. Current information is correct but more content will probably be added in the future.

SCP (secure copy) is a very widely used linux command for copying files across machines over the network.

You can upload files from your machine to remote servers and/or download files from remote server to your local machine, using standard SSH authentication.

Simply put, scp enables your to run cp (default copy command) to/from a remote machine, the same way ssh enables you to log in and run a shell on a remote machine.

scp is to cp as ssh is to sh

Simplest Usage (upload a file from your machine to a remote server)

$ scp <username>@<ip>:/home/<username>/Downloads

Upload a file using an Identity key

$ scp -v -i <identityFileLocation> <fileLocation> <remoteUsername>@<remoteHostOrIP>:

Where all values within "<" and ">" should be replaced with your own values;

  • examples

    sending a single file using a .pem key

    $ scp -v -i ~/.ssh/key.pem data.txt  queirozf@

    sending a directory using a .pub key

    $ scp -r -v -i ~/.ssh/ ~/a_directory/ queirozf@a_host:

p.s.: the colon (":") at the end is not a typo.

Download a file FROM the server TO your local machine

$ scp queirozf@<host>:foobar.txt /some/local/directory

Download a file using an identity key (private key)

$ scp -i ~/.ssh/<your_key_name> queirozf@<host>:a_sql_dump.sql ~/backup/

Download directories and subdirectories recursively from a server TO your machine

Use -r modifier. -p is optional; it forces the downloaded files to keep the same "last-modified-timestamps" as the original files.

$ scp -rp <username>@<host>:/path/to/remote/directory/ /path/to/local/target

Dialogue & Discussion