VPS Hosting

VPS Hosting

Build Your VPS

How to use the SCP command

SCP (Secure Copy) is a command-line utility included with most Linux distributions enabling secure file transfers between two networked systems. It uses SSH for authentication and encryption, ensuring transferred files and passwords are protected against unwanted access.

In this guide, we detail basic SCP syntax and how to use secure copy for remote transfers. You’ll need to have set up SSH for your VPS to use SCP.

SCP Syntax

As with most command-line utilities, SCP has a lot of different options. Understanding syntax can fast track your understanding and ability to use it effectively. Below is the most basic example of SCP syntax with a detailed description about each section.

scp [options] source destination

From the start, scp is followed by:

  • options for example adding -r here would make the copy recursive.
  • source is the file or directory you are trying to copy. This is entered in the following format username@remote:/path/to/directory/.
  • destination is where you are sending the file to so following the same format of source but with targets information.

SCP Command Options

There are a number of useful options that you can apply to your SCP command to control its behaviour some of the most relevant include:

  • -P
    This targets a specific port on the source or destination host. This is necessary if the standard SSH port (22) is closed.
  • -p
    This ensures metadata preservation including: ownership, permissions and creation/modification date of that file. This is great when you want a perfect carbon copy of the that file.
  • -q
    Essentially making the command silent, not showing progress status or completion messages. Useful if you are running multiple commands.
  • -C
    This compresses the content as it is sent. More resource intensive in terms of overall load but reduces bandwidth and time significantly from to a smaller payload.
  • -r
    Already mentioned and likely the most used option -r will ensure that directories are copied recursively meaning the directory and its contents will be copied completely.

Example commands

Securely copy from a local system to a remote address.

Copy files and/or directories (with -r) from your local device to a remote system using a similar command to below. Which copies that index.html file to the remote systems public_html directory.

scp /path/to/index.html root@192.168.1.1:/home/public_html

To copy an entire directory and it’s contents you’ll need to add -r as shown below.

scp -r /path/to/images root@192.168.1.1:/home/public_html

Copy from one remote address to another.

Logged in as root (or a user with correct permissions) you can copy the public_html directory from /home/public_html on a server with the IP 192.168.1.1 to another remote host using the following example. Replacing root with your user (if required) and both the source and destination addresses.

scp -r root@192.168.1.1:/home/public_html root@192.168.1.2:/home/public_html

Helpful tips for SCP

There are few options you can apply to the command that if used correctly can improve its effectiveness. In some cases however, it is preferred to use rysnc instead.

Wildcards

You can utilise basic wildcards with SCP to target multiple files or directories in one command. These wildcards include

  • *
    This will match zero or more characters
  • ?
    This matches a single character

When applying a wildcard to a remote host wrap the full source or destination in quotes so it is interpreted remotely. In our example below you can see how using a * wildcard can help by copying all backups from June (using a standardised naming convention) in a single command.

scp "root@192.168.1.2:/home/backups/backup-2025-06-*.tar.gz" root@192.168.1.3:/home/backups/