The scp command is used to copy files and directories between one computer to another. What is valuable about this utility is the fact that it used ssh to tunnel the copying. This means that the data is encrypted because it rides on ssh’s secure features. Before you begin using the scp command make sure that the computer/host that will be receiving the files/directories has sshd installed and listening.

use scp command securely transfer files

You can use ssh keys or password means of authentication. The syntax of scp is fairly simple:

scp [OPTIONS] [files or directories] [[email protected]]:[directory]

The various options for scp are listed below:

  • -3 Copies between two remote hosts are transferred through the localhost. Without this option, the data is copied directly between the two remote hosts. Note that this option disables the progress meter.
  • -4 Forces scp to use IPv4 addresses only.
  • -6 Forces scp to use IPv6 addresses only.
  • -B Selects batch mode (prevents asking for passwords or passphrases).
  • -C Compression enable. Passes the -C flag to ssh(1) to enable compression.
  • -c cipher Selects the cipher to use for encrypting the data transfer. This option is directly passed to ssh(1).
  • -F ssh_config Specifies an alternative per-user configuration file for ssh. This option is directly passed to ssh(1).
  • -i identity_file Selects the file from which the identity (private key) for public key authentication is read. This option is directly passed to ssh(1).
  • -l limit Limits the used bandwidth, specified in Kbit/s.
  • -o ssh_option Can be used to pass options to ssh in the format used in ssh_config(5). This is useful for specifying options for which there is no separate scp command- line flag.
  • -P port Specifies the port to connect to on the remote host. Note that this option is written with a capital ‘P’, because -p is already reserved for preserving the times and modes of the file.
  • -p Preserves modification times, access times, and modes from the original file.
  • -q Quiet mode: disables the progress meter as well as warning and diagnostic messages from ssh(1).
  • -r Recursively copy entire directories.
  • -T Disable strict filename checking.
  • -v Verbose mode. Causes scp and ssh to print debugging messages about their progress.

Examples of using scp

Specifying a different port that the remote ssh host is using apart from default. Option v here adds verbosity.

scp -Pv 2023 /home/tech/index.html [email protected]:/var/www/html

Copy directories to the remote host

scp -Pr 2023 /home/tech/website/ [email protected]:/tmp/

Copying files from a remote host to the local computer

scp [email protected]:/tmp/index.html /home/tech/website

With scp, you can copy files between two remote hosts. This is quite cool.

scp [email protected]:/var/log/messages [email protected]:/tmp/logs/

If you would wish the above remote to remote files transit to pass through your local machine, then add the -3 option as below:

scp -3 [email protected]:/var/log/messages [email protected]:/tmp/logs/

If you would wich to preserver the access times, modification times and modes from the original file, use small p option

scp -pv /home/tech/index.html [email protected]:/tmp/

scp can take advantage of ssh’s compress feature while transferring the files.

scp -Cr /home/tech/website/ [email protected]:/tmp/ ## Passes the -C flag to ssh to enable compression.

In order to disable the progress meter as well as warning and diagnostic messages from ssh while using scp, use -q option

scp -pqr /home/tech/website/ [email protected]:/tmp/


scp command comes in handy especially for the remote to remote copying of files. Never be frustrated again about transferring your important data from one host to another.

Also, check:

How to use rsync command on Linux/Unix with examples

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here